Nah*_*byr 6 objective-c uitableview ios
我有一个带菜单的默认主 - 细节表视图.该菜单有效,但出于某种原因,按下"+"按钮在我的应用中添加另一个单元格时出现以下错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符Cell将单元格出列 - 必须为标识符注册一个nib或类或连接一个storyboard中的原型单元格'
我搜索了几天的解决方案
如果我添加到viewDidLoad:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
Run Code Online (Sandbox Code Playgroud)
我没有收到错误,但添加的单元格不是我的故事板中配置的单元格,也没有指向详细视图控制器.
我已多次检查原型单元格的标识符字段是否已填写并且与*cellIdentifier相同.
据我所知,它似乎与这里提出的问题具有相同的性质.
任何帮助将不胜感激,如果你有时间,请解释为什么我做了什么或为什么应该添加某些代码.
请求的代码(两者都是Xcode 5.0.1添加的默认代码):
// Code to add the button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
// Code called when button is pressed:
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
还可以查看评论中添加的图片和项目文件
将以下行替换为[MAAppDelegate application:didFinishLaunching]
UINavigationController *masterViewController = [[UINavigationController alloc] initWithRootViewController:[MAMasterViewController new]];
Run Code Online (Sandbox Code Playgroud)
和
UINavigationController *masterViewController = (UINavigationController *)self.window.rootViewController;
Run Code Online (Sandbox Code Playgroud)
当应用程序到达 时didFinishLaunching,已经从故事板配置了根视图控制器(如果您查看故事板,根视图控制器就是带有指向它的箭头的控制器)。请注意,此过程依赖于initWithCoder:初始化程序。
您将didFinishLaunching丢弃此视图控制器,并将其替换为 的实例,您已使用和TWTSideMenuViewController的新非故事板实例配置了该实例。如果您考虑一下,就无法知道它应该从特定的故事板元素进行配置。实际上有一个 API 用于从故事板实例化视图控制器:。但您不需要这样做,因为它已经为您完成了。UINavigationControllerMAMasterViewController[MAMasterViewController new][storyboard instantiateViewControllerWithIdentifier:]
所以解决办法很简单。TWTSideMenuViewController只需使用现有的根视图控制器进行配置即可self.window.rootViewController。
| 归档时间: |
|
| 查看次数: |
17400 次 |
| 最近记录: |