如何从UITableView获取所选行? [英] How can you get the selected rows from a UITableView?

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

问题描述

所以我编写了这段代码,在我要选中的行旁边放置一个复选标记,因为我想要多个选定的行

So I've written this code to put a checkmark beside a row that I want selected because I want multiple selected rows

UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

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

但是当我使用这个方法时:

but when I use the method:

NSArray *selectedIndexPaths = [self.LightsView indexPathsForSelectedRows];

它只获取我点击的最后一行。复选标记是否未选中它?

it only gets the last row that I clicked on. Is the checkmark not selecting it?

推荐答案

对于 indexPathsForSelectedRows:方法要正常工作,您必须配置表视图以允许多个单元格选择:

For the indexPathsForSelectedRows: method to work properly, you have to configure the table view to allow multiple selection of cells:

tableView.allowsMultipleSelection = YES;

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

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