Batnom
Batnom

Reputation: 279

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.

Upvotes: 2

Views: 10483

Answers (5)

Bijoy Thangaraj
Bijoy Thangaraj

Reputation: 5546

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is also not called when the tableview's height is not set.

Upvotes: 2

verma
verma

Reputation: 753

This is a older link, but I wanted to update this with putting info on how I resolved this issue. For me the issue was the Array to populate the table had 0 rows so cellForRowAtIndexPath was never called. Make sure that the Array you are using to populate the table has data in it.

Upvotes: 0

NJones
NJones

Reputation: 27147

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];
}

Upvotes: 9

hellozimi
hellozimi

Reputation: 1878

It seems you're missing UITableViewDelegate.

If you're using Interface Builder, right click the table view outlet and drag both delegate and datasource to File's Owner.

And if not using Interface Builder add this where you init your tableView

bigTable.delegate = self;
bigTable.dataSource = self;

Remember to import the UITableViewDelegate and UITableViewDataSource protocols, just as Srikar says.

Hope this is to any help.

Cheers!

Upvotes: 3

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73698

Maybe you did not set the tableView delegate as self or the datasource as self. Add this code & see if it works now -

[tableView setDelegate:self];
[tableView setDataSource:self];

Also in your header file inherit these delegates - UITableViewDelegate, UITableViewDataSource

@interface yourViewController: UIViewController <UITableViewDelegate, UITableViewDataSource>

Hope this helps.

Upvotes: 0

Related Questions