0

嗨,就像标题一样,index.row 永远不会变为 4,而是从 [2,0] 开始。我的 tableView 有 5 行。我不知道它什么时候停止工作,但我确定它在我添加 timeIndex 行之前工作。

这是我在显示时遇到问题的“在此处输入地址”字段

let timeIndex = 2
let DateLocation = 1
let locationIndex = 4
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {



    if userPickedDate && indexPath.row == timeIndex {
        return 50
    }
    if userPickedDate && indexPath.row == DateLocation {

        return 0

    }
    print("The indexPath: \(indexPath)")
    if remindMeOnLocationSwitch.isOn && indexPath.row == locationIndex {
        return 100

    }
    if remindMeOnDay.isOn && indexPath.row == DateLocation{
        return 300
    } else if indexPath.row == DateLocation || indexPath.row == timeIndex || indexPath.row == locationIndex  {
        return 0
    }
    return 50

}

表视图

控制台输出

控制台输出

4

3 回答 3

0

您可以检查 numberOfRowsInSection 中的内容

    func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
    if(section == 0){
    return 1
    }
    else if(section == 1){
        return 2
    }else{
        return 3
    }

}

在 numberOfRowsInSection 中设置的行数应该是错误的

于 2017-07-26T09:13:50.497 回答
0

每个部分将有不同的行数。这就是为什么您的 indexPath 永远不会变为 4。[2,0] 表示第 2 节中的第 0 行。您可以根据如下部分检查行:-

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0{

    }else if indexPath.section == 1{

    }else if indexPath.section == 2{
         if indexPath.row == 0{
            // here is your fifth row return height for fifth row
         }
    }

}
于 2017-07-26T09:14:23.603 回答
0

我发现了我忘记更新 numberOfRowsInsideSection 函数内的行数的问题

 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    // Change from [1,4,1] to [1,5,1]
    let numberOfRowsInSection: [Int] = [1,5,1]
    var rows: Int = 0

    if section < numberOfRowsInSection.count {
        rows = numberOfRowsInSection[section]
    }

    return rows
}
于 2017-07-27T07:35:17.747 回答