【发布时间】:2012-01-01 23:27:03
【问题描述】:
我正在定制我的单元格,如下所示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"reusedCell";
DetailCell *cell = (DetailCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Customize the cell of each row from table
if ( cell == nil ) {
NSLog(@" MY CELL IS NIL");
cell = [[DetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else
NSLog(@" MY CELL IS NOT NIL");
}
通过调试,我知道根本没有到达第 4-5 行
MY CELL IS NOT NIL
因此,我无法创建自己的单元格。根据苹果文档
通常,数据源应该做的第一件事是将 dequeueReusableCellWithIdentifier: 发送到表视图,并传入重用标识符字符串。如果表格视图没有返回可重用的单元格对象,则数据源会创建一个,在 initWithStyle:reuseIdentifier 的最后一个参数中为该对象分配一个重用标识符:
因此,在我的情况下,表格视图确实返回了一个可重用的单元格对象......它从何而来...... 以前有没有人遇到过这个问题。请帮忙谢谢。
【问题讨论】:
标签: iphone ios cocoa-touch