Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cellForRowAtIndexPath not being called

I have a view that adds another view on top in this manner:

- (void)showAreaEditView {

    NSLog(@"SHOWING AREA EDITOR VIEW");

    if (self.thisAreaEditorView == nil) {

        // Create View
        AreaEditorView *tmpViewController = [[AreaEditorView alloc] initWithNibName:@"AreaEditorView" bundle:nil];
        self.thisAreaEditorView = tmpViewController;
        [tmpViewController release];

        // Hide the back button
        self.thisAreaEditorView.navigationItem.hidesBackButton = YES;

    }

    self.thisAreaEditorView.myInspectionID = self.myInspectionID;
    self.thisAreaEditorView.loggedIn = loggedIn;
    self.thisAreaEditorView.loggedInGroup = loggedInGroup;

    // Slide view up

    [self.view addSubview:thisAreaEditorView.view];


    CGRect endFrame = CGRectMake(self.view.frame.size.width/2 - thisAreaEditorView.view.frame.size.width/2,
                                 self.view.frame.size.height/2 - thisAreaEditorView.view.frame.size.height/2, 
                                 thisAreaEditorView.view.frame.size.width, 
                                 thisAreaEditorView.view.frame.size.height);

    CGRect startFrame = endFrame; // offscreen source

    // new view starts off bottom of screen
    startFrame.origin.y += self.view.frame.size.height;
    self.thisAreaEditorView.view.frame = startFrame;

    // start the slide up animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.6];   
    thisAreaEditorView.view.frame = endFrame; // slide in
    [UIView commitAnimations];

}

I'm sure you can just ignore the slide part, I feel the addSubview is relevant.

Then in thisAreaEditor I have the view with the table and buttons and such. UITableView delegate/datasource is going to File's Owner as normal.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSLog(@"numberOfRowsInSection returning %d", [tableData count]);
    [tableData count];

}

This function numberOfRowsInSection returns 4

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *thisText =  [tableData objectAtIndex:indexPath.row];
    cell.textLabel.text = thisText;

    NSLog(@"looking at cell %d text:%@", indexPath.row, thisText);

    return cell;

}

But cellForRowAtIndexPath never gets called.

I'm at a loss here, I have no idea how it can seem to work fine but one of the delegate functions simply not be called.

I have tried [bigTable reloadData] and so on, the table just never gets populated and no logs from the function output.

Thanks in advance.

like image 482
Batnom Avatar asked Jun 30 '26 03:06

Batnom


1 Answers

You might have just edited this out, if so I'm sorry, but it looks like you forgot to return tableData's count.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"numberOfRowsInSection returning %d", [tableData count]);
    return [tableData count];
}
like image 63
NJones Avatar answered Jul 01 '26 17:07

NJones