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

Magnus
  • 2,016
  • 24
  • 32
gh0st
  • 214
  • 3
  • 15
  • Are the labels in `AgentTableRowController` set to something other than nil? I know several times when I've tried populating table rows, the outlets are sometimes randomly set to nil – prawn Mar 19 '15 at 15:29
  • If it was nil the App would crash while accessing agentLabel property in row. – gh0st Mar 19 '15 at 15:33
  • 6
    Try calling `loadTableData()` in the `willActivate()` method – dan Mar 19 '15 at 15:45
  • Worked like a charm!! Post it as an answer and I'll mark it. – gh0st Mar 19 '15 at 15:49
  • possible duplicate of [Why am I getting an error "Failed to locate or generate matching signing assets" in Xcode 6?](http://stackoverflow.com/questions/25862917/why-am-i-getting-an-error-failed-to-locate-or-generate-matching-signing-assets) – memmons Apr 01 '15 at 17:35
  • i'm getting the same results, but only in the simulator, and only when the table is on the second or later page of a paged interface. the table on the first page is fine in the simulator, and all tables are fine on the actual hardware. note that willActivate() will also be called when returning from a force touch menu. – bunnyhero May 29 '15 at 10:18
  • i should clarify that by "getting the same results," i mean that i'm experiencing the same bug from the original question. – bunnyhero May 29 '15 at 10:29

2 Answers2

2

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.

bengoesboom
  • 2,119
  • 2
  • 23
  • 27
0

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..

Tim
  • 284
  • 2
  • 10
  • No dice, I even tried this: ` let row = agentTable.rowControllerAtIndex(0) as AgentTableRowController row.agentLabel.setText("Agent1")` Nothing works. – gh0st Mar 19 '15 at 14:53
  • agents.count gives you the correct value if you println it in init()? – Tim Mar 19 '15 at 14:57
  • yes, everything is tip top. all the indices, the values print correctly. The first 4 rows are just not populated. Maybe it's a bug. – gh0st Mar 19 '15 at 14:59
  • if let row = agentTable.rowControllerAtIndex(i) as? AgentTableRowController {row.agentLabel.setText(agents[i]) }. Try this – Tim Mar 19 '15 at 15:23