[英]I don't know why the result is not my have thought
This is my code. 这是我的代码。 What I want to do is to show the detail(the last 3 rows at every section) when I did select one of the first row in all sections. 我要做的是显示确实的细节(每个部分的最后3行),当我确实选择了所有部分的第一行时。
The var People is a Set type and its value is [] default and when one row was selected, it would append the current section to this Set and then when we return numberOfRows, we can depend on the People Set and decide which Section should be show only one row and which should be 4 rows. var People是一个Set类型,其值是[]默认值,当选择了一行时,它将当前节附加到此Set中,然后当我们返回numberOfRows时,我们可以依赖People Set并确定应将哪个节设为仅显示一行,应为4行。
But the result is whichever row I selected the numberOfRowsInSection is always 1. 但是结果是无论我选择的哪一行numberOfRowsInSection始终为1。
Anybody can tell me Why it came this? 谁能告诉我为什么会这样?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if Peoples.isEmpty {
return 1
}
else{
if Peoples.contains(section) {
return 4
}
else {
return 1
}
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
TV.deselectRowAtIndexPath(indexPath, animated: true)
if Peoples == []{
Peoples.insert(indexPath.section)
}
else {
if Peoples.contains(indexPath.section){
Peoples.remove(indexPath.section)
}
else {
Peoples.insert(indexPath.section)
}
}
println("\(Peoples)")
}
Okay,Nobody can help me but I have fixed this problem.Because I forgot to reloadData when I didSelectAtindexPath. 好的,没有人可以帮我,但我已经解决了这个问题。因为当我执行SelectSelectindexPath时,我忘记了重新加载数据。
This is my worked code updated. 这是我的工作代码更新。
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if Peoples.isEmpty {
return 1
}
else{
if Peoples.contains(section) {
return 4
}
else {
return 1
}
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
TV.deselectRowAtIndexPath(indexPath, animated: true)
if Peoples == []{
Peoples.insert(indexPath.section)
}
else {
if Peoples.contains(indexPath.section){
Peoples.remove(indexPath.section)
}
else {
Peoples.insert(indexPath.section)
}
}
tableView.reloadData()
println("\(Peoples)")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.