您好,谢谢大家。我有一个表格视图,允许用户更改为剖视图。在标准视图中一切正常,但是当用户切换到剖视图时,当我尝试使用 (-commitEditingStyle:) 函数删除一行时,我崩溃了。我在这个功能中缺少什么?分段时我应该如何删除一行?(我从一个 plist 加载我的表,它是一个数组字典。每个索引都是 tableview 中的一行。)
- (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.
}
//////////////////////////////////
}
}
控制台:-[__NSCFString removeObjectAtIndex:]:无法识别的选择器发送到实例 0xe4bd3f0
如您所见,我一直在玩弄格式....不确定下一步该尝试什么???谢谢。
我所说的分段是什么意思: