我在向UITableView添加新行时遇到了麻烦.我在stackoverflow上读了类似的问题,谷歌搜索,...没有帮助我.
我有空的NSMutableArray*dataForList和UITableView的数据.点击屏幕后,我想添加新行.此错误显示:
*因未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'尝试将第0行插入第0部分,但更新后第0部分只有0行'
码:
NSArray *insertIndexPaths = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:
[self.dataForList count] // is zero now
inSection:0]];
[self.dataForList addObject:newRow];
// [self.dataForList count] is 1 now
[self.unsignedTableView beginUpdates];
[self.unsignedTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.unsignedTableView endUpdates]; // on this line error ocours
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
所有UITableView方法
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath {}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return [self.mainController.dataForList count];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{
return 38.0f;
}
- (UITableViewCell *) tableView: (UITableView *) tableView
cellForRowAtIndexPath: (NSIndexPath *) indexPath {
// call render method in view, it works fain
return [self.signUpToTestView renderUnsignedCell:tableView cellForRowAtIndexPath:indexPath];
}
Run Code Online (Sandbox Code Playgroud)
确保您创建的表视图具有委托和数据集.
例如:
[self.unsignedTableView setDelegate:self];
[self.unsignedTableView setDatasource:self];
Run Code Online (Sandbox Code Playgroud)
我认为这次崩溃的原因是数据源和委托方法没有被调用
| 归档时间: |
|
| 查看次数: |
19027 次 |
| 最近记录: |