I want to set my UIImage to WKInterfaceImage, but the simulator shows only black screen.
It works OK using setImageNamed: NSString* method, but not with setImage: UIImage* . My file1.png is added to "(App Name) WatchKit App" folder.
- (void)willActivate {
[self.imageView1 setImage: [UIImage imageNamed: @"file1"]]; // doesn't work
[self.imageView1 setImageNamed: @"file1"]; // works OK
[super willActivate];
}
Thanks!
Everything is working as expected.
file1 is in your WatchKit App folder, which means it is on the watch.
Calling [UIImage imageNamed:] loads from the main bundle, which doesn't contain file1, so you get nil.
The way you are doing this is correct. setImageNamed: will look for images on the Watch first, then in the cache.
Calling [UIImage imageNamed:imageName] from your extension will always return nil for a cached image. The image is cached on the watch — not in your extension.
Once an image is cached, it allows you to set a WKInterfaceImage using the [WKInterfaceImage setImageNamed:] method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With