2012-08-03 67 views
0

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

這裏是我的code.In Viewcontroller.m

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

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


[self presentModalViewController:nav animated:YES];  
} 

在我的第一泰伯維控制器命名爲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]; 

} 

命名爲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中的描述顯示Viewcontroller它的工作原理.. 請指導我...

+3

'原因: '數據源的UITableView必須返回從的tableView細胞:的cellForRowAtIndexPath:' ***網絡第一次調用堆棧:'這是你的問題。' 你應該總是在'cellForRowAtIndexpath'方法中返回一個'cell'。 – iNoob 2012-08-03 10:24:36

+2

你的'-tableView:cellForRowAtIndexPath:'方法在哪裏實際拋出異常? – holex 2012-08-03 10:30:47

+0

退貨單元已在那裏.. – Dany 2012-08-03 10:42:09

回答

0

這裏的解決方案是在第二個表視圖控制器添加條件如果單元爲零它必須顯示錶視圖style.Add將下面的代碼

的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; 
} 
相關問題