UITableView:我可以删除多行吗? [英] UITableView: can I delete multiple rows?

查看:69
本文介绍了UITableView:我可以删除多行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户的选择从表视图中删除多行.显然,我不能使用didSelectRowAtIndexPath方法,因为将为每个选定的行调用该方法.我想允许用户选择要删除的多行,然后一次性删除它们.是否有可能?

I want to delete multiple rows from a table view, based on the user's selection. Obviously I can't use the didSelectRowAtIndexPath method because it will be called for every row selected. I want to allow the user to select multiple rows for deletion and then delete them in one go. Is it possible?

如果是,那么该怎么做?另外,我正在使用基于单视图的项目,并且当用户希望从视图中删除行时,我希望在同一视图上将表视图的标题更改为删除".

If yes, then how to go about it? Also, I am using a single-view-based project and I want the header of the table view changed to "Delete", on the same view, when the user wants to delete the rows from the view.

推荐答案

您可以通过以下方式进行操作:

You can do something this way:

- (void)tableView:(UITableView *)theTableView
      didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {

[theTableView deselectRowAtIndexPath:[theTableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [theTableView cellForRowAtIndexPath:newIndexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [selectedCellsMutableArray addObject:newIndexPath];
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    cell.accessoryType = UITableViewCellAccessoryNone;
    [selectedCellsMutableArray removeObjectIdenticalTo:newIndexPath];
}

}

当用户按下 Delete Selected (删除所选内容)按钮时-只需调用

When user press Delete Selected button - just invoke something like

// change your model here and then:
[yourView deleteRowsAtIndexPaths:selectedCellsMutableArray
                withRowAnimation:UITableViewRowAnimationRight];

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

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