繁体   English   中英

UITableView reloadData之后出现NSInternalInconsistencyException异常

[英]NSInternalInconsistencyException after UITableView reloadData

我在reloadData之后在链接到我的UITableViewNSMutableArray添加对象时遇到问题...

我收到此错误:

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:7344
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

添加:

self.relatedArtists = [[NSMutableArray alloc]init];

Artist* test = [[Artist alloc]init];
test.name = @"Test 1";
[self.relatedArtists addObject:test];

Artist* test2 = [[Artist alloc]init];
test2.name = @"Test 2";
[self.relatedArtists addObject:test2];

[self.artists reloadData];

numberOfRowsInSectioncellForRowAtIndexPath

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [self.artists dequeueReusableCellWithIdentifier:@"ARTIST_CELL_ID"];

    Artist *artist = self.relatedArtists[indexPath.row];
    cell.textLabel.text = artist.name;

    return cell;
}

我想我错过了Main.storyboard文件中的Main.storyboard内容,但看不到...

我认为您错过了将故事板上的tableView单元格的标识符设置为ARTIST_CELL_ID

您还必须使用给定的reusablecellidentifier“ ARTIST_CELL_ID”注册tableviewcell。

示例代码如下。

[yourTableView registerNib:[UINib nibWithNibName:@"YouTableViewCellNibName" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM