我正在尝试使用 Apple 提供的“编辑”-> (-) -> “删除”功能从我的 UITableView 中删除一行。
我在这里激活了按钮:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
此处创建的 UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
PositionCell *cell = (PositionCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[PositionCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
FSExAppDelegate *appDelegate = (FSExAppDelegate *)[[UIApplication sharedApplication] delegate];
Position *pos = [appDelegate.positions objectAtIndex:indexPath.row];
[cell setPosition:pos];
// Configure the cell.
return cell;
}
然后是 Apple 提供的代码:
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[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.
}
}
当我执行删除操作时,我卡在了:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
使用“线程 1:程序接收到信号‘SIGABRT’”。
我一直在搜索这里的问题,但似乎找不到有关此问题的任何信息。谁能帮忙?
音乐总监。
最佳答案
我认为你遗漏了:
[mutableArrayAsDataSource removeObjectAtIndex:[indexPath row]];
这可能应该在 deleteRowsAtIndexPaths 调用之前发生。
关于objective-c - UITableViewCell 上的 SIG_ABRT 删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5429891/