2012-12-02 36 views
0

我試圖從一個視圖控制器過渡到編程表視圖控制器(與用故事板SEGUE),使用此代碼:斷言錯誤使用pushViewController時將TableViewController

[self.navigationController pushViewController:photosTVC animated:YES]; 

不過,我得到表視圖控制器加載時出現「斷言錯誤」;具體而言,在此方法的第二行:使用SEGUE轉變到它時

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Photo"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
... 

表視圖控制器加載罰款,但只是不是當我過渡這種方式。任何想法,我可以嘗試將非常感激!

感謝您的閱讀。

編輯:完整的錯誤文本是如下:在

斷言故障 - [UITableView的dequeueReusableCellWithIdentifier:forIndexPath:],/SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460

+0

什麼是完整的錯誤? – rmaddy

回答

1

要使用[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];該單元必須使用registerNib:forCellReuseIdentifier:registerClass:forCellReuseIdentifier:進行註冊,如果您正在使用故事板,則可以完成該操作。

因此,如果您正在以編程方式進行此操作,請使用此方法[tableView dequeueReusableCellWithIdentifier:CellIdentifier],除非有具體原因不要。

編輯:

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    // or whatever cell initialisation method you have/created 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 
+0

感謝您的回覆。由於我確實需要在方法的後面訪問indexPath,它看起來像我需要實現registerNib/registerClass。如果我仍然需要在使用segue進行轉換時保留功能,我是否應該實現兩種註冊方法? – Rogare

+0

即使您只使用[tableView dequeueReusableCellWithIdentifier:CellIdentifier],您仍然可以訪問indexPath,tableView:cellForRowAtIndexPath:仍然會爲您提供indexPath。你將實現registerNib/registerClass取決於你在做什麼,你是否創建UITableViewCell的子類,或者你只是使用NIB文件原型化單元格,但我仍然認爲你可以用[tableView dequeueReusableCellWithIdentifier:CellIdentifier]逃脫。 –

+0

好吧,通過使用這種方法,原來的錯誤現在消失了。謝謝!然而,它確實在這裏旅行:斷言失敗 - [UITableView _configureCellForDisplay:forIndexPath:],/ SourceCache /UIKit_Sim/UIKit-2372/UITableView.m:5471 – Rogare