6

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:

empty rows

Scroll further:

enter image description here

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

4

2 回答 2

2

我在初始化我的表时遇到了完全相同的问题awakeWithContext。通过按照 dan 的建议将我的表初始化移动到willActivate该问题已解决。

我筛选了两者的文档,WKInterfaceController他们WKInterfaceTable建议您应该能够在initor中执行初始化awakeWithContext,所以我认为这是 WatchKit 框架中的一个错误。

于 2015-05-01T14:17:54.110 回答
0

也许用索引的for循环试试?

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

希望对你有用..

于 2015-03-19T14:52:39.957 回答