use*_*503 2 storyboard tableview ios
我使用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];
}
Run Code Online (Sandbox Code Playgroud)
但是当我点击该行时它会给我以下错误:
*由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'UITableView dataSource必须从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;
}
Run Code Online (Sandbox Code Playgroud)
我假设这是错误发生的地方,单元格返回一个nil值.当我尝试使用或从按钮附加iSubProducts tableviewcontroller时,它一切正常,但如果它来自行的单击,则会出现此错误.
我对iOS开发很新,也许从tableviewcontroller打开tableviewcontroller时出现错误,上面有一个自定义单元格.我已经连续两天呆了脑子并且用Google搜索了很多,不幸的是我找不到任何解决方案.我很确定iSubProducts tableviewcontroller上没有错误,因为如果我尝试从按钮推送它,它的工作原理.我需要关于这个问题的建议,我现在对这个问题非常感兴趣.谢谢大家.
请注意这是多么有益..但就在今天,我在点击行后无法从一个tableview移动到另一个视图..
我完全远离了DidSelectRowAtIndexPath.相反,我使用了segue(这是我的目标).
剪切的代码来自苹果的故事板示例,它使用表格.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowSelectedPlay"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都可以让您开始在故事板功能中使用segue,并确保使用segues的标识符.
| 归档时间: |
|
| 查看次数: |
5089 次 |
| 最近记录: |