Hi I am new to WatchKit
development. I want to know that can I update a single interface controller with multiple data for button clicks
You could have many different objects in your InterfaceController, such as labels, image views, etc.
Updating WKInterfaceLabel
s
You should call the setText() method on the corresponding label.
For example, you have a button and a label, and you want to print "Hello" on the label when the button is clicked. In this case, you should connect an action to the button in your interface (by control-dragging button to the code), and then add the following code in the method created:
Swift
label1.setText("Hello")
Objective-C
[label1 setText:@"Hello"];
Updating WKInterfaceImage
s
You should call setImage() or setImageNamed() methods on the corresponding image view.
First, the image should be located in the Asset Catalog of your WatchKit App Target, must be bundled or available as an UIImage
. Then you could use these codes:
Case #1: Available as file in bundle or Asset Catalog
Swift
image1.setImageNamed("imageName")
Objective-C
[image1 setImageNamed:@"imageName"];
Case #2: Available as an UIImage
Swift
image1.setImage(image)
Objective-C
[image1 setImage:image];
If you want to have animated photos, try this link.
Conclusion
WKInterfaceLabel
s, you should call the setText() method on the corresponding label.WKInterfaceImage
s, you should call setImage() or setImageNamed() methods on the corresponding image view.Resources