2012-04-25 238 views
0

我正在研究一个项目,我需要在表格中填充单元格并让它们显示在屏幕上。我有表格显示,但现在数据显示在单元格中。我试过使用断点,发现这个方法永远不会被调用。它之前的方法(numberOfRowsInSection)确实被调用。有什么建议么?cellForRowAtIndexPath不被调用?

- (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]; 
     } 
     Resident *aResident = (Resident *)[appDelegate.residents objectAtIndex:indexPath.row]; 
     cell.textLabel.text = aResident.name; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     return cell; 
    } 

回答

0

您是否设置了TableView的委托和数据源?

+0

既然他说numberOfRowsInSection被调用,那些似乎设置.... – Mario 2012-04-25 20:32:05

+0

dint注意到..我的坏..所以它应该是,numberOfRows/numberOfSections返回0 .. – Roshit 2012-04-25 20:48:28

+0

你是对的,计数是归零。现在我只需要弄清楚为什么数组会返回零计数。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)部分NSLog(@“Count =%i”,[appDelegate.residents count]); return [appDelegate.residents count]; – 2012-04-26 15:53:31

0

是的,numberOfRowsInSection可能返回0.显示它并在其中填充数据源。

相关问题