我有一个部分表格,其中包含部分,我想删除特定的单元格交换并删除此单元格,并从表格中删除该单元格,并从数组中删除。commitEditingStyle问题 - 删除表格中的单元格
以及如何在删除单元格时动画。
对于我下面的代码,但不工作请帮助做到这一点。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.reports removeObjectAtIndex:indexPath.row];
[tbl reloadData];
[tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
得多多个R & d再之后,我建立了新的代码和它成功运行
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[[[self.reports objectAtIndex:indexPath.section] valueForKey:@"events"] removeObjectAtIndex:indexPath.row];
[tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationLeft];
[NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(tableReload) userInfo: nil repeats: NO];
}
}
-(void)tableReload{
[tbl reloadData]; }
你能分享你的'cellForRowAtIndexPath:'方法吗? –
我创建自定义单元格,并把它放到表 –
我只是想看看你是如何分配文本到单元格,以检查你是否删除正确的数组对象。你提到了分段tableview,这意味着你需要检索indexpath的行和段,但你只检查行。无论如何,很好,你的问题现在得到解决 –