Swift indexpath.row在表内视图高度FORROWAT 3后重置
您好,就像标题所说的那样,index.row永远不会变为4,而是从[2,0]开始。我的tableView有5行。我不知道它什么时候停止工作,但我确信在添加timeIndex行之前它已经工作了 这是“在此处输入地址”字段,我在显示时遇到问题Swift indexpath.row在表内视图高度FORROWAT 3后重置,swift,uitableview,heightforrowatindexpath,indexpath,Swift,Uitableview,Heightforrowatindexpath,Indexpath,您好,就像标题所说的那样,index.row永远不会变为4,而是从[2,0]开始。我的tableView有5行。我不知道它什么时候停止工作,但我确信在添加timeIndex行之前它已经工作了 这是“在此处输入地址”字段,我在显示时遇到问题 let timeIndex = 2 let DateLocation = 1 let locationIndex = 4 override func tableView(_ tableView: UITableView, heightForRowAt inde
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
}
控制台输出
您可以在NumberOfRowsin部分中查看您拥有的内容
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
if(section == 0){
return 1
}
else if(section == 1){
return 2
}else{
return 3
}
}
在numberOfRowsInSection中设置的行数应该是错误的每个节将有不同的行数。
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
if(section == 0){
return 1
}
else if(section == 1){
return 2
}else{
return 3
}
}
这就是为什么你的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
}
}
}
我发现问题在于我忘记更新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
}
override func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
//#警告未完成实现,返回行数
//从[1,4,1]更改为[1,5,1]
让numberOfRowsInSection:[Int]=[1,5,1]
变量行:Int=0
如果节 你的表视图中有多少个部分?3个第一个文本框,然后是一个中间的提醒,而最后一个是[今天的星期五],你可以看一看,你会明白为什么你的索引路径永远不会到4Hi。我不确定你是否误解了我,但它是“在此处输入地址”行我在显示时遇到问题,而不是分段控制器