Image is not visible on Watch App programatically

Multi tool use
Image is not visible on Watch App programatically
I have a very weird issue. I have a watch app and I am trying to display an image programatically. When I debug the code, I can see the image is correctly loaded but on simulator or real device I cannot see the image. I have added that image in both watch and extension bundle resources.
Firstly I use the code below to open the view.
NSArray *objects =[NSArray arrayWithObjects:@"MainPageView",@"InterfaceController",@"PoseImageView",nil];
[self presentControllerWithNames:objects contexts:nil];
Inside PoseImageView
I am trying to display an image with:
PoseImageView
UIImage *imgTest = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg", strAngle]]; // I can see 1.jpg in debugger
[_imgPose setImage: imgTest];
The image is not there on watch or simulator. I am wondering how to fix the issue.
Note: From assets its not loading as well.
Note2: I can only display the image if the view is initial view.
It's not about the definition of UIImage. I tried what you wrote as well.
– birdcage
Jul 2 at 13:26
check your image its valid .jpg by checking its get info and name is correct and added in target / build files i.stack.imgur.com/v3Z0A.jpg
– 9to5ios
Jul 2 at 13:27
I tried many images in assets catalog or bundle resources. I just cannot display it unless the view is not initial view.
– birdcage
Jul 2 at 13:30
check this stackoverflow.com/questions/27299572/…
– 9to5ios
Jul 2 at 13:30
1 Answer
1
You are trying to use imageNamed for .jpg which will not work.
Try using
NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"imageName"] ofType:@"jpg"];
UIImage *theImage = [UIImage imageWithContentsOfFile:filePath];
Didn't help. I can already see image in debugger but can't show it on display.
– birdcage
Jul 2 at 12:49
Did u add the image in watchkit extension’s asset catalog?
– Karthick Ramesh
Jul 2 at 13:01
Yes I added it.
– birdcage
Jul 2 at 13:06
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
UIImage *imgTest = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg", strAngle]]; // I can see 1.jpg in debugger Syntax seems incorrect ? Use it UIImage *imgTest = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg"]]; // I can see 1.jpg in debugger
– 9to5ios
Jul 2 at 13:25