iphone - 在 UITableview 中选择多行

标签 iphone uitableview

我想在 UITableview 中选择多行,就像 Apple 在 native Alarm 应用程序中所做的那样(参见图片 alt text

我怎样才能做到这一点?

到目前为止我看到的所有答案都是旧的(并说“不能做”)或引用 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/

相关文章:

ios - PebbleFramework给了我很多警告和错误

ios - 以编程方式创建的 UITableView 的弹性标题 - Swift

iphone - 比较今天或昨天的 NSDate

ios - NSFetchedResultsController 只获取前 10 个项目

iphone - 对于iOS healthkit如何保存收缩压和舒张压值?

iphone - 如何开始使用 airplay?

ios - 当我尝试在 App Store 上上传新版本时,applink 出现 iTunes 错误 90046

iphone - 核心数据错误 133020 : problems merging in a save:

ios - swift -UITableView 'unable to dequeue a cell with identifier Cell'

ios - CollectionView 委托(delegate)方法未从 TableViewCell 调用