0

我创建了一个基于视图的应用程序并在其中添加了两个表视图控制器。这是我按下 Viewcontroller 按钮的事件流-> 加载表视图控制器,如果选择了一个单元格-> 显示第二个表控制器。

这是我的代码。在 Viewcontroller.m

-(IBAction)product:(id)sender
 {
Products *sec=[[Products alloc]init];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:sec];


[self presentModalViewController:nav animated:YES];    
}

在我的第一个名为 products.m 的 Tableview 控制器中

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.

 Description *detailViewController = [[Description alloc] initWithNibName:@"Description" bundle:nil];
 // ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detailViewController animated:YES];




 [detailViewController release];

}

我的第二个 TableView 控制器命名为 description。现在问题是我的第二个 tableview 控制器没有显示,我遇到的问题是

 *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:],     /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
 2012-08-03 15:10:51.016 jothi R&D[1112:f803] *** Terminating app due to uncaught  exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a  cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x13d3022 0x1564cd6 0x137ba48 0x9b42cb 0xb7d28 0xb83ce 0xa3cbd 0xb26f1 0x5bd21 0x13d4e42  0x1d8b679 0x1d95579 0x1d1a4f7 0x1d1c3f6 0x1d1bad0 0x13a799e 0x133e640 0x130a4c6 0x1309d84  0x1309c9b 0x12bc7d8 0x12bc88a 0x1d626 0x22a2 0x2215 0x1)
terminate called throwing an exception

但是,如果我尝试通过替换 products.m 中的描述来显示 Viewcontroller,它会起作用..请指导我...

4

1 回答 1

0

这里的解决方案是在第二个 Tableview 控制器中添加条件如果单元格为 nil 它必须显示表格视图样式。在中添加以下代码

cellForRowAtIndexpath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)  
{        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];



}

// Configure the cell...

return cell;
}
于 2012-08-03T12:42:16.047 回答