cellForRowAtIndexPath not being called
Solution 1
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];
}
Solution 2
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!
Solution 3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
is also not called when the tableview's height is not set.
![Batnom](https://i.stack.imgur.com/ZVnTK.jpg?s=256&g=1)
Batnom
Updated on June 04, 2022Comments
-
Batnom about 2 years
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.
-
Batnom over 12 yearsStill doesn't work unfortunately. In
viewWillAppear
I callpopulateTableData
function which triggers[bigTable reloadData]
sotitleForHeaderInSection
gets called (returning nothing), thennumberOfRowsInSection
(returns 4), then that's it. -
Batnom over 12 yearsOh my, you're right. I was missing the
return
innumberOfRowsInSection
. Can't belive it was that simple, thank you! -
lizzy81 almost 8 yearsim using a switch statement in
numberOfRowsInSection
to handle 8 different sections. and overlooked not including the wordreturn
. some problems can be so silly to solve.