![](/img/trans.png)
[英]I have a working swipe detector script, but I don't know how to connect it to my character controller
[英]I don't know why the result is not my have thought
这是我的代码。 我要做的是显示确实的细节(每个部分的最后3行),当我确实选择了所有部分的第一行时。
var People是一个Set类型,其值是[]默认值,当选择了一行时,它将当前节附加到此Set中,然后当我们返回numberOfRows时,我们可以依赖People Set并确定应将哪个节设为仅显示一行,应为4行。
但是结果是无论我选择的哪一行numberOfRowsInSection始终为1。
谁能告诉我为什么会这样?
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)")
}
好的,没有人可以帮我,但我已经解决了这个问题。因为当我执行SelectSelectindexPath时,我忘记了重新加载数据。
这是我的工作代码更新。
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.