无法使用标识符TodoItemRow对单元格进行出列 - 必须为标识符注册一个nib或类,或者在故事板中连接原型单元格'

时间:2015-05-11 01:08:02

标签: ios objective-c

获得以下错误。

***由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'无法使用标识符TodoItemRow对单元格出列 - 必须为标识符注册一个nib或类或连接原型故事板中的单元格'

我有点理解为什么会这样,但有点不然。任何帮助将不胜感激。

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic) NSMutableArray *items;

@end

@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.

   self.items = @[@{@"name" : @"Take out the trash", @"category" : @"Home"}].mutableCopy;

   self.navigationItem.title = @"What needs to be done";
}

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

#datasource

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellItentifier = @"TodoItemRow";
    UITableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:CellItentifier forIndexPath:indexPath];

    NSDictionary *item = self.items[indexPath.row];

    cell.textLabel.text = item[@"name"];

    return cell;
}

@end

3 个答案:

答案 0 :(得分:2)

您应在此处添加标识符

enter image description here

答案 1 :(得分:1)

您使用过xib还是故事板?如果您使用它,您可以将标识符设置为&#34; TodoItemRow&#34;并将[self.tableView registerNib:<#(nullable UINib *)#> forCellReuseIdentifier:<#(nonnull NSString *)#>] 添加到您的VC。

答案 2 :(得分:0)

我明白了。我有一个案例问题。我的单元格标识符是totoitemrow,但我在代码中将其键入为TodoItemRow。