I am just getting started with iPhone development. I’ve done some tutorials to get the general feel of Xcode and Objective C. I’ve been searching for the proper way to do this simple task but everything I have tried comes up empty. For now I am just trying to read in a .jpg file from my desktop and display it in the iPhone simulator. The code I am currently using is:
- ( void )viewDidLoad {
UIImage *img = [UIImage imageNamed:@"/Users/jinser/Desktop/cow.jpg"];
//UIImage *img = [UIImage imageNamed:@"cow.jpg"];
[imgView setImage:img];
[super viewDidLoad]; }
and in my Interface file I have:
@interface MainViewController: UIViewController {
IBOutlet UIImageView *imgView;
}
@end
I do not receive any errors, but the simulator opens up with no image displayed. I’ve also tried adding the image to my project resources and using the second line of code that I have commented about but it gives me the same result.
Any ideas? Ultimately I will use OpenCV functions to do some processing on the image, but i need the image to be read in correctly first obviously.
Thanks for any help!
It’s quite complicated to answer your question without details.
I made a simple project that reach you needs. Check it and you’ll find out why your code doesn’t work.
Sample Project