Apple Watch Table - first 4 rows not appearing

I'm having trouble adding rows to WKInterfaceTable in Apple Watch. The strange thing is that no matter what I do, the first 4 lines look empty. I tried adding lines manually and in a loop - it doesn't matter. I believe my code is good because the fifth and subsequent lines look just fine. Here's what happens:

empty rows

Scroll further:

enter image description here

My code is:

 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. This is probably something trivial. I am running Xcode 6.2 (6C131e) on Yosemite 10.10.2

+6
source share
2 answers

I had the same problem when initializing my table in awakeWithContext . By moving the table initialization to willActivate , as suggested, dan problem has been resolved.

I sifted through the documentation of both WKInterfaceController and WKInterfaceTable , and they suggest that you should initialize in init or awakeWithContext , so I believe this is an error in the WatchKit structure.

+2
source

Maybe try with 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 this works for you.

0
source

Source: https://habr.com/ru/post/984012/


All Articles