【发布时间】:2015-10-16 23:53:04
【问题描述】:
我在 tableview 控制器中使用自定义单元格类。
当我在 cellForRowAtIndexPath NSLog(@"method called"): 的 tableviewcontroller 中包含一条语句时,它似乎没有被调用。
当您有自定义单元格时,是否可能不调用此方法?
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cell for row at index path called");
NSDictionary *item= [self.getItems objectAtIndex:indexPath.row];
//This sets place in storyboard VC
IDTVCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.item = item;
if (cell == nil) {
cell = [[IDTVCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell"];
}
return cell;
}
【问题讨论】:
-
用您的实际
cellForRowAtIndexPath方法更新您的问题。还要确保您的数据源方法返回的行数非零。 -
numberofrowsinsection 方法返回指定的多个,即 return 1 返回 1。但是,似乎没有调用 cellforrowatindexpath。
-
如果你有非零部分和非零行,那么应该调用
cellForRow...方法。你确认numberOfRowsInSection:被调用了吗? -
是的,它肯定被称为。在viewdidload之前按照控制台中的顺序。我想知道自定义单元格是否对此有影响。
-
这是
UITableViewController还是UIViewController加上UITableView?如果是后者,表格视图的框架是否设置正确?self.getItems是如何初始化的?
标签: ios objective-c uitableview