首页 > 解决方案 > 如何通过单击 UITableView 的上一个单元格来解锁下一个单元格?

问题描述

问题:如何阻止输入cell(№ 2,3,4,5 ...)?以及如何使它在您单击 №1 时cell打开 №2 cell在此处输入图像描述

标签: iosswiftuitableview

解决方案


有一个包含未锁定行索引的数组。

var unlockedRows: [Int] = [1]

现在您可以检查该行是否已解锁或不在didSelectRowAt委托中。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if unlockedRows.contains(indexPath.row) {
        let nextIndex = indexPath.row + 1
        if nextIndex < numberOfRows { //Use your variable that gives total number of rows here instead of numberOfRows
            unlockedRows.append(indexPath.row + 1)
            // Do other stuff like removing the locked icon of the next cell
        }
        return true
    }
    // Display row locked message?
    return false
}

推荐阅读