UITableView多项选择 [英] UITableView Multiple Selection

查看:95
本文介绍了UITableView多项选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的基于视图的应用程序中添加UITableView,用户将点击多个单元格,它将被选中,就像时钟应用程序的新警报设置名为重复(时钟>警报) > +>重复),如何获取数组中的所有选定单元格?

How can I add a UITableView into my View-Based Application where the user will tap on more than one cell, and it will become selected, exactly like the Clock app's "New Alarm" setting named "Repeat" (Clock>Alarms> + >Repeat), and how can I get all of the selected cells in an array?

推荐答案

在执行 -tableView:didSelectRowAtIndexPath:你可以设置表格视图单元格的 accessoryType 属性,具体取决于它的当前值(所以它会打开和多次点击关闭)。例如:

In your implementation of -tableView:didSelectRowAtIndexPath: you would set the table view cell's accessoryType property depending on its current value (so it would toggle on and off with multiple taps). For example:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    } else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

您可以另外维护一系列选定状态到单元格自己的附件类型状态,或迭代表视图中的单元格查询每个状态,以便读出所选行。

You could either maintain an array of selected states in addition to the cells' own accessory type state, or iterate over the cells in the table view querying for each one's state in order to read out the selected rows.

这篇关于UITableView多项选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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