iphone - 如何从 UITableView 中删除选定的行?

标签 iphone ios uitableview ios4

<分区>

Possible Duplicate:
change Table to Edit mode and delete Rows inside a normal ViewController

我想从 tableView 中删除选定的行。我想为用户提供当他在行上滑动或轻弹手指时删除行的功能。我知道编辑风格,它提供了一个带有 -ve 符号的圆形红色按钮。

我试过这段代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{


[tableView beginUpdates];    
if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Do whatever data deletion you need to do...
    // Delete the row from the data source
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];      
}       
[tableView endUpdates];
[tableView reloadData];
}

我得到了删除按钮,但是当我点击它时出现了 SIGABRT 错误。

最佳答案

尝试像下面几行:

[bookmarks removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];

bookmarks 是我在表格 View 单元格上加载的数组名称,您应该用数组名称代替它。

关于iphone - 如何从 UITableView 中删除选定的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14191057/

相关文章:

快速关闭 View 后,iOS 应用程序卡住

iphone - 如何制作 UIScrollView 图片库? (iPhone SDK)

ios在不退出应用程序的情况下以编程方式进行调用

ios - 如何在 uitableviewcontroller 中动态添加单元格?

ios - UIRefreshControl 被我的 UINavigationController 的 UINavigationBar 隐藏/遮挡

ios - 应用程序在设备上崩溃但在模拟器中没有崩溃 :[UITableViewController loadView] loaded the "XXXViewController" nib but didn't get a UITableView. '

iphone - 从 iOS 应用程序开发转向 Mac 应用程序开发时需要克服的最大障碍是什么?

iphone - iPhone 5 的 hw.machine 有什么值(value)?

ios - 传递依赖项,包括使用Google Map和集群的静态二进制文件

ios - 将 iPhone 应用程序上传到 AppStore 的步骤