UITableView 重新加载数据后出现 NSInternalInconsistencyException
NSInternalInconsistencyException after UITableView reloadData
在 reloadData
...
之后添加链接到我的 UITableView
的 NSMutableArray
中的对象时出现问题
我收到这个错误:
*** 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];
numberOfRowsInSection
& cellForRowAtIndexPath
:
- (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
文件中遗漏了一些东西,但我没看到什么...
我认为您错过了将 Storyboard 中的 tableView 单元格标识符设置为 ARTIST_CELL_ID
。
您还必须使用给定的可重用单元格标识符注册 uitableviewcell "ARTIST_CELL_ID"。
示例代码如下。
[yourTableView registerNib:[UINib nibWithNibName:@"YouTableViewCellNibName" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];
在 reloadData
...
UITableView
的 NSMutableArray
中的对象时出现问题
我收到这个错误:
*** 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];
numberOfRowsInSection
& cellForRowAtIndexPath
:
- (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
文件中遗漏了一些东西,但我没看到什么...
我认为您错过了将 Storyboard 中的 tableView 单元格标识符设置为 ARTIST_CELL_ID
。
您还必须使用给定的可重用单元格标识符注册 uitableviewcell "ARTIST_CELL_ID"。
示例代码如下。
[yourTableView registerNib:[UINib nibWithNibName:@"YouTableViewCellNibName" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];