我有一個部分表格,其中包含部分,我想刪除特定的單元格交換並刪除此單元格,並從表格中刪除該單元格,並從數組中刪除。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的行和段,但你只檢查行。無論如何,很好,你的問題現在得到解決 –