如何从UITableView中删除所选行? [英] How can I delete selected row from UITableView?

查看:104
本文介绍了如何从UITableView中删除所选行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

将表更改为编辑模式并删除普通ViewController中的行

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

I want to delete selected row from tableView. I want to provide the functionality to the user to delete the row when he slips or flicks his finger on the row. I know the editing style which provides a circular red button with -ve sign on it.

我试过这段代码:

- (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错误就在那里。

I get the delete button but when I click it SIGABRT Error is there.

推荐答案

尝试以下几行:

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

书签是我在表视图单元格上加载的数组名称,您应该使用数组名称代替这个。

bookmarks is my array name that I load on table view cell you should give your array name in place of this.

这篇关于如何从UITableView中删除所选行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆