簡體   English   中英

從tableviewcontroller加載tableviewcontroller無法正常工作

[英]Loading a tableviewcontroller from a tableviewcontroller not working

我創建了一個基於視圖的應用程序,並在其中添加了兩個表視圖控制器。這是我的事件流程:按下了Viewcontroller按鈕->加載了Tableview控制器,如果選擇了一個單元格->顯示了第二個表控制器。

這是我的代碼。在Viewcontroller.m中

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

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


[self presentModalViewController:nav animated:YES];    
}

在我的第一個Tableview控制器中,命名為products.m

- (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.Now問題是我的第二個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它的工作原理說明顯示視圖控制器..請指導我...

這里的解決方案是在Second 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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM