How can I add some buttons programmatically in swift 2 using WatchKit?
Asked
Active
Viewed 748 times
1 Answers
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
-
Thanks! I am trying to use table but I am not finding good examples. Have you got any one? – Nisba Jul 29 '15 at 10:55
-
@LucaMarconato Check the updated link about tutorial – Ashish Kakkad Jul 29 '15 at 10:58
-
@LucaMarconato Welcome anytime. :) – Ashish Kakkad Jul 29 '15 at 11:03