2

I'm trying to build a simple WatchKit app with a Table. Each row has a Label. Here's my TableRowController class:

import WatchKit

class TaskTableRowController: NSObject {

    @IBOutlet var taskName: WKInterfaceLabel!
}

In my InterfaceController, I add a row to my Table and try to set the Label's text. However, taskList.rowController(at: 0) does not find a row, so the Label is unmodified.

import WatchKit
import Foundation

class InterfaceController: WKInterfaceController {

    @IBOutlet var taskList: WKInterfaceTable!

    override func awake(withContext context: Any?) {
        super.awake(withContext: context)

        // Configure interface objects here.
        taskList.setNumberOfRows(1, withRowType: "TaskRow")
        if let x = taskList.rowController(at: 0) as? TaskTableRowController
        {
            x.taskName.setText("Hello World")
        }
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}

Here's some screens from Interface Builder and the output: Interface Builder Watch Simulator

csstudent
  • 77
  • 2
  • 5

1 Answers1

0

Replace Following code, It works for me :

    taskList.setNumberOfRows(10, withRowType: "TaskRow")

    for index in 0..<taskList.numberOfRows {
        if let controller = taskList.rowControllerAtIndex(index) as? TaskTableRowController {
            controller.taskName.setText("Hello World")
        }
    }

I have seen the screen shots but pl. Cross check & Make sure below points :

  • WKInterfaceLabel(taskName) has an IBOutlet in your TaskTableRowController.

  • TaskTableRowController identifier is set to 'TaskRow'.

  • WKInterfaceTable(taskList) has an IBOutlet.

  • The custom class for your row 'TaskTableRowController' is set.

Hope it helps you !!!

Do let me know if you have any query.

Ketan P
  • 4,259
  • 3
  • 30
  • 36