iPhone: "initWithNibName:bundle:"的 TableViewController nibName 错误

标签 iphone objective-c ios uitableview nib

我有一个动态单元格 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/

相关文章:

ios - iOS 应用程序中谷歌地图上的实时交通状况?

iphone - 如何从 JSON 中获取 bool 值?

iphone - UIPickerView 如何显示未选择的内容?

iphone - iPhone的Twitter API?

ios - 使用 cocoapods 在 watch OS 2 上进行 AFNetworking

iOS 从 HealthKit 读取数据

ios - 如何根据键盘管理 ScrollView (向上和向下)在 Objective-C 中使用 NSNotificationCenter 在屏幕中显示和隐藏

ios - 限制 UIDate View 滚动到旧日期?

iphone - 如何打印或记录 CGSize 对象的值?

ios - 如何在 iOS 中获取电池温度详细信息?