1

How can I add some buttons programmatically in swift 2 using WatchKit?

o.k.w
  • 25,490
  • 6
  • 66
  • 63
Nisba
  • 3,210
  • 2
  • 27
  • 46

1 Answers1

1

You can't dynamically create views in WatchKit. You need to create your entire interface in a storyboard. You can have elements of your storyboard hidden and then programmatically unhide them.

Reference : Create imageView programmatically in Watch Kit

You can create table instead of the buttons. So, you can get multiple clickable links.

Here is tutorial by @natashatherobot http://natashatherobot.com/watchkit-create-table/

Snippet from the tutorial :

private func loadTableData() {
    minionTable.setNumberOfRows(minions.count, withRowType: "MinionTableRowController")
    for (index, minionName) in enumerate(minions) {
        let row = minionTable.rowControllerAtIndex(index) as! MinionTableRowController
        row.interfaceLabel.setText(minionName)
        row.interfaceImage.setImage(UIImage(named: minionName))
    }
}
Community
  • 1
  • 1
Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136