【问题标题】:Could not load NIB in bundle: 'NSBundle - TableView无法在包中加载 NIB:'NSBundle - TableView
【发布时间】:2013-11-30 22:44:56
【问题描述】:

我想了解 TableViewController 的工作原理,但每次尝试运行我的小测试应用程序时都会出错。

它显示以下错误:

错误:

TabelViewSB[13074:70b] * 由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',
原因:'无法在包中加载 NIB:'NSBundle /Users/xxxx/Library/Application 支持/iPhone模拟器/7.0.3/ 应用/F8138200-E111-40BA-8C0C-0B42E91A5312/TabelViewSB.app (已加载)' 名称为 '故事板''

代码 TableViewController.h:

#import <UIKit/UIKit.h>

@interface TableViewController : UITableViewController

@end

代码 TableViewController.m :

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


    // Configure the cell...
    cell.textLabel.text = [NSString stringWithFormat:@"zeile %i",indexPath.row];
    return cell;
}

我做了什么:

  • 创建新项目 -> 空应用程序
  • 创建了一个故事板(主界面是故事板)
  • 将 TabelViewController 添加到 Storyboard
  • 创建了一个新类“TableViewController”来处理它...

我在论坛上阅读了很多关于该问题的信息并尝试了给出的解决方案: (没用……)

  • 产品 -> 清洁(按 ↑、cmd、K)
  • 已删除派生数据 ...我也试过了
  • 添加捆绑包...但我没有得到它...

如果有人能给我一点提示,我将非常感激。

提前致谢

【问题讨论】:

  • 通过使用 iOS Simulator -> Content and Preferences reset 重置 iOS Simulator 解决了第一个问题
  • 请将代码粘贴到你初始化tableviewcontroller的地方..
  • 你的数组有 30 个对象?如果它小于 30,它可能会因为您的代码而产生一些错误。

标签: ios objective-c xcode storyboard


【解决方案1】:

您是否重命名了 XCode 之外的一些文件?例如在 Finder 中?如果是这样,您需要重新命名它们。

对于未来:在 XCode 之外更改项目中的任何内容通常是一件坏事。它会为您处理几乎所有事情。

【讨论】:

  • 注册 tableViewcell 时,可能会出现额外的 nib 名称空格
【解决方案2】:

请在情节提要中将 TableViewController 中单元格的可重用标识符作为“单元格” 希望这能解决您的问题。

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多