objective-c - UITableViewCell 上的 SIG_ABRT 删除

标签 objective-c ios uitableview

我正在尝试使用 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/

相关文章:

ios - UILabel 文本行设置为方形排列 iOS

ios - 如何同时更新每个自定义tableview单元格数据?

ios - 在 UITableViewScrollPosition 之后找到 UITableViewCell 的 UIView frame

ios - 推送 View Controller 时,UISearchController searchBar 不会消失

ios - 方法 "not available on iOS"

ios - FBSDKAccessToken currentAccessToken 登录后未更新

iphone - arc4random 抛出大量数字

ios - 为什么不能更改 UITableViewController 中的按钮宽度

iphone - UIWebView 中横向模式的 Youtube 视频

ios - 如何取消归档 NSManagedObject