这是我的问题:
我有一个NSMutableArray *notes
和我的来源UITableView* _gradesTV
。
我在- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
这里添加了方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"%ld", (long)indexPath.section);
NSLog(@"%@", notes);
[_gradesTV beginUpdates];
[notes removeObjectAtIndex:indexPath.section];
[_gradesTV deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
[_gradesTV endUpdates];
NSLog(@"%@", notes);
}
[_gradesTV reloadData];
}
但是当我删除一个元素时,我得到了这个错误:
*** Terminating app due to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
但是我在 MutableArray 上制作的 NSLog 向我展示了 3 个元素......
removeObjectAtIndex
注释上的行(MutableArray)使我的应用程序崩溃,就像它被执行了两次一样......
谢谢您的帮助 ...
如果你想拉项目并尝试......
您必须使用 + 按钮创建成绩,然后您可以尝试删除我的表格视图中的项目。
添加成绩时,第一个 TextField 是 a string
,第二个是一个double
值,第三个也是一个double
值。