栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

IOS Swift 4中的TableView CheckMark和Uncheck With滚动仍选中的单元格值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IOS Swift 4中的TableView CheckMark和Uncheck With滚动仍选中的单元格值

我认为,如果有人要运行您的代码,则不会显示任何错误。但是如果有真实数据,它可能会。的 原因存储您的选中标记方式
。您

temp
应该在存储数组的实际值时将一行的数据存储
indexPath
到数组中,以便 只有该行才具有选中标记
。在您的情况下,如果一行
1
内有标签,然后单击它,则该单元格将突出显示。现在,如果您开始滚动并且包含另一个单元格,
1
则该行也将突出显示。

对于单节,我已经修改了您的示例。如果有多个部分,则需要存储

indexPath
而不是
indexPath.row

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {    var cell = tableView.dequeueReusableCell(withIdentifier: "id")    cell = UITableViewCell.init(style: .default, reuseIdentifier: "id")    cell?.textLabel?.text = String(numarr[indexPath.row])    if temp.contains(indexPath.row) {        cell?.accessoryType = .checkmark    } else {        cell?.accessoryType = .none    }    return cell!}func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {    let cell = tableView.cellForRow(at: indexPath)    if temp.contains(indexPath.row) {        cell?.accessoryType = .none        temp.remove(at: indexPath.row)    } else {        cell?.accessoryType = .checkmark        temp.append(indexPath.row)    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636370.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号