你好,謝謝大家。我有一個表格視圖,允許用戶切換到分區視圖。所有的標準視圖都很好,但是當用戶切換到剖視圖時,我試圖用(-commitEditingStyle :)函數刪除一行時崩潰。我在這個功能中缺少什麼?當它被分割時,我應該如何刪除一行? (I從一個plist中wchich是陣列的字典加載我表的每個索引是在tableview中的行。)如何在使用部分時編輯(即刪除行)uiTableView?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([strTitle isEqualToString:@"sectionView"]) {
@try {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
// NSMutableDictionary *book =[[NSMutableDictionary alloc]init];
NSMutableDictionary *mynewList = [[NSMutableDictionary alloc]init];
mynewList = [[self.TitleDis valueForKey:[[[self.TitleDis allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
NSMutableArray *sectionRow = [mynewList objectForKey:@"Dis"];
[sectionRow removeObjectAtIndex:indexPath.row];
[mynewList writeToFile:[self dataFilePath] atomically:YES];
//
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
@catch (NSException *exception) {
NSLog(@"hello error...%@",exception);
}
}
else {
/////////////////////// STANDARD VIEW
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[distribArray removeObjectAtIndex:indexPath.row];
//
// NSMutableArray *contents = [[NSMutableArray alloc] init];
// [contents addObject:myMasterList];
// //[contents addObject:[NSArray arrayWithObjects:arraydata.text,distroName.text,destorEmail.text, nil]];
[distribArray writeToFile:[self dataFilePath] atomically:YES];
//
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
//////////////////////////////////
}
}
CONSOLE: - [__ NSCFString removeObjectAtIndex:]:無法識別的選擇發送到實例0xe4bd3f0
正如你所看到的,我一直在玩格式....不知道接下來要嘗試什麼?謝謝。
我的意思切片:
「分段視圖」是什麼意思?你的意思是表格視圖的分組樣式? – Tobi