Reputation: 287
I have added images in image assets in watchApp target and now I am trying to Load an array with these images. But every time I am getting image as nil. ex. added A1.png, A2.png, A3.png......in image asset in watchApp target. Now, trying to get image with image name as... UIImage *img = [UIImage imageNamed:@"A1"];
But, every time I am getting nil.
Upvotes: 1
Views: 46
Reputation: 2417
Issue is that you have added the images in your WatchApp target and trying to load the image through an API which will search the images in your WatchExtention bundle. To understand this we need to see how images are being searched in bundles for WatchApp and WatchExtention.
Let's take an example that we have an object of WKInterfaceImage
say objImage
.
WKInterfaceImage *objImage
;
When you use the method [objImage setImageNamed:@"abc"
], system send the name of image to WatchApp and search for the image in WatchApp bundle not in the Extention bundle.
However when you specify your images in Extention target(bundle) then to use these images they need to be transferred to WatchApp target using imageNamed:
method, which will search the image in Extention bundle not in WatchApp bundle.
So if you want to use the imageNamed:
API, you need to specify your images in Extention target as well. However this has some overhead of it's own and i suggest not to use unless necessary.
Check the Apple Documentation:Section - Using Named Images to Improve Performance for detailed reference.
Upvotes: 1