如果我删除自己部分中的最后一个单元格,则需要删除部分
如果我删除以结尾开头的部分-效果很好,但是如果我删除第一部分-应用程序崩溃
和我的最后一部分-添加按钮
怎么了 ?
我的代码
- (void)deleteExerciseFromCustomTable:(NSIndexPath *)indexPath {
[[_exercises objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
[_previewTable beginUpdates];
[_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[_previewTable endUpdates];
if ([[_exercises objectAtIndex:indexPath.section] count] == 0) {
[_group removeObjectAtIndex:indexPath.section];
[_previewTable beginUpdates];
[_previewTable deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];
[_previewTable endUpdates];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == [_group count]) {
return 1;
}else{
return [[_exercises objectAtIndex:section] count];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [_group count] + 1;
}
我解决了我的问题
- (void)deleteExerciseFromCustomTable:(NSIndexPath *)indexPath {
if ([[_exercises objectAtIndex:indexPath.section] count] == 1) {
[_group removeObjectAtIndex:indexPath.section];
[_exercises removeObjectAtIndex:indexPath.section];
[_previewTable beginUpdates];
[_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[_previewTable deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];
[_previewTable endUpdates];
}else{
[[_exercises objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
[_previewTable beginUpdates];
[_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[_previewTable endUpdates];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句