我想在 UITableview 中选择多行,就像 Apple 在 native Alarm 应用程序中所做的那样(参见图片
我怎样才能做到这一点?
到目前为止我看到的所有答案都是旧的(并说“不能做”)或引用 native 邮件应用程序中的多行选择。该方法不是我想要的,因为您必须首先进入“编辑”模式。我希望能够立即选择行。
希望有人能帮忙。
基督教
最佳答案
我发现的最简单的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
您可以通过调用以下命令来查看选择了哪些单元格:
NSArray *selectedCells = [self.tableView indexPathsForSelectedRows];
关于iphone - 在 UITableview 中选择多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4616345/