【发布时间】:2014-03-20 19:42:29
【问题描述】:
尝试填充我的表格时出现此错误:
* -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] 中的断言失败
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *dictionary = tasks[indexPath.row];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = dictionary[@"key"];
cell.detailTextLabel.text = [Global getPriority:(NSString *)dictionary[@"key_2"]];
return cell;
}
当我删除 forIndexPath 时,错误消失,但我可以使用 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法。
有人可以帮帮我吗?
此外,该表是通过编程方式构建的。
谢谢,
彼得
【问题讨论】:
-
您使用什么版本的 iOS 来运行此代码?我唯一能猜到你使用的是 iOS 5.0,但这种方法
dequeueReusableCellWithIdentifier:forIndexPath:(developer.apple.com/library/ios/documentation/uikit/reference/…) 仅适用于 6.0
标签: ios objective-c uitableview