Apple Watch Table - first 4 rows not appearing

我的梦境 提交于 2020-01-22 20:54:28

问题


I'm having problems adding rows to WKInterfaceTable on Apple Watch. The weird thing is that no matter what I do, the first 4 rows appear as empty. I tried adding rows manually and in a loop - doesn't matter. I believe my code is good because 5th and further rows appear just fine. Here's what happens:

Scroll further:

My code:

import Foundation
import WatchKit

class TableInterfaceController: WKInterfaceController{

    @IBOutlet weak var agentTable: WKInterfaceTable!

    let agents = ["The Dude","Walter","Donnie","Maude","Knox","Karl","Nihilist 2"]

    override init(){
        super.init()
        loadTableData()
    }


    private func loadTableData(){
        agentTable.setNumberOfRows(agents.count, withRowType: "AgentTableRowController")
        println("Count: \(agents.count)")

        for(index,agentName) in enumerate(agents){
            let row = agentTable.rowControllerAtIndex(index) as AgentTableRowController
            println(agentName, index)
            row.agentLabel.setText(agentName)
        }
    }
}

Any help appreciated. It's probably something trivial. I'm running Xcode 6.2 (6C131e) on Yosemite 10.10.2


回答1:


I was having the exact same issue when initializing my table in awakeWithContext. By moving my table initialization into willActivate as suggested by dan the issue was solved.

I sifted through the documentation of both WKInterfaceController and WKInterfaceTable and they suggest that you should be able to perform the initialization in init or awakeWithContext, so I believe this is a bug in the WatchKit framework.




回答2:


Maybe try it with the indexed for-loop?

for var i=0; i<agents.count; i++ {
   let row = agentTable.rowControllerAtIndex(i) as AgentTableRowController
        println(agents[i], i)
        row.agentLabel.setText(agents[i])
}

Hope that works for you..



来源:https://stackoverflow.com/questions/29147205/apple-watch-table-first-4-rows-not-appearing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!