【发布时间】:2011-12-13 19:50:53
【问题描述】:
我使用 xcode 4.2 和 storyboard 创建了一个 iOS 选项卡式应用程序。我添加了一个带有自定义单元格的tableviewcontroller,单击该行时,我想打开一个tableviewcontroller,我使用了下面的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
categoryClass *cc = [datas objectAtIndex:indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
iSubProducts *subProducts = [[iSubProducts alloc] init];
subProducts.title = cc.categoryName;
subProducts.catID = cc.categoryID;
[[self navigationController] pushViewController:subProducts animated:YES];
[subProducts release];
}
但是当我点击该行时,它给了我以下错误:
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath 返回一个单元格
在我的 iSubProducts tableviewcontroller 上,我有以下内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myCell2";
iSubProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
productSubClass *cc = [datas2 objectAtIndex:indexPath.row];
NSLog(@"Product Name: %@", cc.productName);
cell.txtProductName.text = cc.productName;
cell.txtProductDesc.text = cc.productDesc;
return cell;
}
我认为这是发生错误的地方,单元格返回 nil 值。当我尝试使用或从按钮附加 iSubProducts tableviewcontroller 时,一切正常,但如果它来自单击的行,则会出现此错误。
我对 iOS 开发很陌生,可能从带有自定义单元格的 tableviewcontroller 打开 tableviewcontroller 时出错。我现在已经头疼了 2 天了,用谷歌搜索了很多,不幸的是我没有找到任何解决方案。我很确定 iSubProducts tableviewcontroller 没有错误,因为如果我尝试从按钮按下它,它就可以工作。请我需要关于这个的建议,我现在很纠结这个问题。谢谢大家。
【问题讨论】:
标签: ios tableview storyboard