Reputation: 715
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!
Upvotes: 10
Views: 4350
Reputation: 4244
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.
Upvotes: 1
Reputation: 16865
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.
Upvotes: 14