简体   繁体   English

我不知道为什么结果不是我想的

[英]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.

相关问题 我有一个有效的滑动检测器脚本,但我不知道如何将它连接到我的角色控制器 - I have a working swipe detector script, but I don't know how to connect it to my character controller stringWithContentsOfFile无法转换我的文件,我也不知道为什么 - stringWithContentsOfFile can't convert my file and I don't know why 我的 TableView 数据源函数没有被调用,我不知道为什么 - My TableView datasource functions aren't being called and I don't know why 我的程序经常是死锁,我不知道为什么,如果我使用coredata - My program is often a deadlock,I don't know why,If I used coredata 我不知道为什么我的 Tableview 在选择行时没有推送 DetailView - I don't know why my Tableview did not push the DetailView when row is selected 我不知道如何将弹出框与按钮对齐 - I don't know how to align my popovers to button 我不知道为什么在swift3中没有调用viewForHeaderInSection - I don't know why viewForHeaderInSection is not called in swift3 我不知道为什么这个表视图代码崩溃了 - i don't know why this table view code crashes iOS组件会自动调整大小,但我不知道在哪里以及为什么 - iOS Component is automatically resizing but I don't know where and why 不知道为什么我的声音无法在我的应用程序中播放? - Don't know why my sound won't play in my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM