如何标记多个 UITableViewCell 并对标记的单元格执行操作?

发布于 2024-08-20 15:18:18 字数 168 浏览 5 评论 0原文

我想做的几乎与邮件应用程序所做的一样:当我选择“编辑”时,而不是通常的“删除”按钮,单选按钮出现在用户可以检查的一侧,然后用户可以单击一个按钮来采取对标记单元格的操作(任何类型的操作,不仅仅是删除)。有没有苹果示例代码可以做到这一点?任何人都可以提供一些关于如何执行此操作的代码或文档吗?谢谢。

-奥斯卡

I would like to do pretty much what the Mail Application does: that when I select Edit, instead of the usual Delete Button, Radio Buttons appear on the side that may be checked by the user, then the user may click on a Button to take an action on the marked cells(any kind of action not just delete). Is there any apple sample code that does this?, can anyone please provide some code or documentation on how to do this?. Thank you.

-Oscar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简美 2024-08-27 15:18:18

我还没有这样做,所以以下所有内容都直接来自文档。我将这样做:

  1. 覆盖视图控制器的 setEditing:animated: 方法,以在表格进入编辑模式时显示一个或多个按钮来执行批处理操作(就像 Mail.app 所做的那样) 。
  2. 为您的单元格使用自定义 UITableViewCell 子类。
  3. 关键是在自定义单元类中覆盖 willTransitionToState:。在此方法中,将包含单选按钮的自定义子视图添加到单元格中。
  4. 覆盖 layoutSubviews 以将单选按钮和单元格的其余内容放置在单元格中。
  5. tableView:didSelectRowAtIndexPath:中,区分正常状态和编辑状态。如果表格处于编辑模式并且用户点击某个单元格,则将其标记为已选择(相应地修改单选按钮子视图)并保留所有标记单元格的记录。

I haven't done this so all of the following comes straight from the documentation. This is how I would do it:

  1. Overwrite your view controller's setEditing:animated: method to display one or more buttons to execute your batch action (just like Mail.app does) when the table goes into editing mode.
  2. Use a custom UITableViewCell subclass for your cells.
  3. The key is to overwrite willTransitionToState: in your custom cell class. In this method, add a custom subview containing your radio button to the cell.
  4. Overwrite layoutSubviews to position the radio button and the rest of the cell's content in the cell.
  5. In tableView:didSelectRowAtIndexPath:, differentiate between the normal and editing states. If the table is in editing mode and the user taps a cell, mark it as selected (modify your radio button subview accordingly) and keep a record of all marked cells.
给妤﹃绝世温柔 2024-08-27 15:18:18

这是一篇关于进行邮件样式多项选择的好文章:

http://cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html

Here is a good article about doing a Mail-style multiple selection:

http://cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文