2017-07-26 27 views
0

喜欢标题说,index.row永远不会到4,而是重新开始到[2,0]。我的tableView有5行。我不知道它什么时候停止工作,但我确信它在添加timeIndex行之前已经工作。indexpath.row在3之后重置tableView heightForRowAt

它其中我有显示

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 

} 

tableview

控制台输出

Console output

+0

你有多少部分进入你的表视图? –

+0

3一个在哪里第一个文本框是,然后一个在中间这个reminmeomday开始,最后一个是[今天周todo]的东西 –

+0

我发表了一个答案,你可以看看,希望你会明白为什么你的indexPath永远不会去4 –

回答

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 
} 
0

的问题在 “输入地址这里的” 场你可以查阅一下你在数量上有区间

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

} 

应该在numberOfRowsInSection

0

每区设置的行错号码都会有不同的行数。 这就是为什么你indexPath从来就没有到4 [2,0]的意思是行中节号0 2 你可以根据这样的部分检查行: -

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 
     } 
    } 

} 
+0

我怎么能让第五行显示呢? –

+0

嘿,我不确定你是否错过理解我,但它是“输入地址在这里”行我有一个问题显示,而不是segmentControll –

相关问题