是否可以将 UITableView 配置为允许多选? [英] Is it possible to configure a UITableView to allow multiple-selection?

查看:32
本文介绍了是否可以将 UITableView 配置为允许多选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 iPhone,是否可以将 UITableView 配置为允许多选?

For the iPhone, is it possible to configure a UITableView such that it will allow multiple-selection?

我已经尝试为每个 UITableViewCell 覆盖 -setSelected:animated:,但是试图捏造所需的行为很棘手,因为很难将真正的取消选择与 UITableView 认为我的取消选择区分开来'由于选择了另一个单元格,已取消选择!

I've tried overriding -setSelected:animated: for each UITableViewCell, but trying to fudge the required behavior is tricky as it's difficult to separate the real unselections from the ones where the UITableView thinks I've unselected due to selection of another cell!

希望有人能帮忙!

谢谢,

尼克.

推荐答案

最好的方法是对每个选定的行进行复选标记.

The best way to do this would be to a checkmark per selected row.

您可以通过将所选 UITableViewCell 实例上的附件类型设置为 UITableViewCelAccessoryCheckmark 来实现.

You can do that by setting the accessoryType on the selected UITableViewCell instances to UITableViewCelAccessoryCheckmark.

要取消选择该行,请将其重新设置为 UITableViewCellAccessoryNone.

To deselect the row, set it back to UITableViewCellAccessoryNone.

要枚举选择了哪些单元格/行(例如,单击按钮时),只需遍历表格的单元格以查找 UITableViewCellAccessoryCheckmark.或者,在did select"委托方法中管理您的表视图委托中的一些 NSSet 等.

To enumerate which cells/rows were selected (say, upon clicking a button), simply iterate over the cells of the table looking for UITableViewCellAccessoryCheckmark. Or, manage some NSSet or the like in your table view delegate in the "did select" delegate methods.

这篇关于是否可以将 UITableView 配置为允许多选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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