2012-12-02 65 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