我有一个动态单元格 UITableViewController
,我想在有人点击一个单元格时推送一个特定的 View Controller 。所以我尝试使用预制方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是当我进入模拟器并点击一个单元格时,这就是我得到的:
"NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle [...] with name 'AffichageVotesQuestionDuMomentViewController'.
在这个方法中,我有这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
AffichageVotesQuestionDuMomentViewController *detailViewController = [[AffichageVotesQuestionDuMomentViewController alloc] initWithNibName:@"AffichageVotesQuestionDuMomentViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
AffichageVotesQuestionDuMomentViewController
是我自己创建的自定义 View Controller 。我还尝试创建另一个随机的,但我得到了相同类型的错误。如果我将 initWithNibName:
设置为 nil
,它会转至顶部有导航栏的 View Controller ,但它完全是黑色的。
现在,我是一名初级 iPhone 程序员,对 Nib 、 Nib 名称等知之甚少。任何帮助表示赞赏。另外,我没有在 Storyboard 中做任何 segue 或任何事情,因为看起来我正在以编程方式创建 View Controller 并以这种方式推送。不过,如果有使用 segue 的好方法,我也可以接受(但我需要知道点击的单元格所在的行)。
谢谢!
最佳答案
因为您使用的是 IB Storyboard,所以我认为您应该这样做:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"mystoryboard" bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"AffichageVotesQuestionDuMomentViewController"];
... 而不是使用用于经典的基于 xib 的方法的“initWithNibName”初始化程序。
关于iPhone: "initWithNibName:bundle:"的 TableViewController nibName 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13550251/