Swift 3:从UITableView中的数组[Int]获取值

Swift 3:从UITableView中的数组[Int]获取值,swift,uitableview,Swift,Uitableview,我有一个这样的数组[1,2,3,4],有时[1,2,4] 我想在Dinamic数据中实现隐藏和显示UITableViewCell。但是我在获取数组元素时遇到了一个问题。我正在使用for循环,但它似乎不起作用。下面是我的代码: var dataChgSort = [ ["sort" : 0 , "chgSort" : [1, 2, 3, 4, 5] ] , ["sort" : 1, "chgSort" : [1, 2, 3, 4, 5

我有一个这样的数组[1,2,3,4],有时[1,2,4]

我想在Dinamic数据中实现隐藏和显示UITableViewCell。但是我在获取数组元素时遇到了一个问题。我正在使用for循环,但它似乎不起作用。下面是我的代码:

var dataChgSort = [ ["sort" : 0 , "chgSort" : [1, 2, 3, 4, 5] ] ,
                                ["sort" : 1, "chgSort" : [1, 2, 3, 4, 5 ] ] ,
                                ["sort" : 12, "chgSort" : [1, 2, 3, 4, 5] ] ,
                                ["sort" : 2, "chgSort" : [1, 2, 3, 4, 5] ] ,
                                ["sort" : 3, "chgSort" : [4, 5] ] ,
                                ["sort" : 4, "chgSort" : [1, 3, 8, 4, 5] ] ,
                                ["sort" : 8, "chgSort" : [3, 8] ] ,
                                ["sort" : 5, "chgSort" : [1, 3, 4, 5] ] ,
                                ["sort" : 6, "chgSort" : [1, 2, 3] ]
                            ]
.....
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    var height: CGFloat = 0

    let dataRow = ((self.dataChgSort[index] as [String: Any] )["chgSort"] as! [Int]) /*Dinamic Array int [1, 2, 3] or [1,3] etc*/

    self.chgSort = ?????

    if indexPath.row == self.chgSort  {
        height = 0
    } else {
        height = super.tableView(tableView, heightForRowAt: indexPath)
    }
    return height
}

我的理解是,如果数据行显示[1,2,4],那么tableview将显示第1,2和4行的高度。下面是我检查所选数组中是否出现indexath.row的解决方案

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    let dataRow = ((self.dataChgSort[index] as [String: Any] )["chgSort"] as! [Int]) /*Dinamic Array int [1, 2, 3] or [1,3] etc*/

    if dataRow.containse(indexPath.row + 1)  {
       return super.tableView(tableView, heightForRowAt: indexPath)

    } 
    return 0
}

哇,它的工作,但有一个显示匹配。我认为索引总是以0开头,但我会修正它。感谢You@MarioMargoPradipta伟大的我更新答案,使其具有+1