Reputation: 111
I have developed an iPad app using core data to store employee details. I have only three fields: Name, id and department. On launching the application the names are displayed in a table view and on clicking in any row, the respective id and department is displayed in the detail view.
Now I want to display picture of the employees in detail view too but not by storing them in core data. I have a subfolder named "Images" in the resources folder in which the pictures are stored in order of the names displayed in the table view.
Please help me in this regard.
Upvotes: 0
Views: 100
Reputation: 21219
You should read something about transient properties of CoreData entities. You can easily add property image for example, which is transient (= does not store values to underlying persistent store), which can read/write your images directly from your file system. In other words, you can have everything in one place and no entity in one class, image handling in another, etc.
Upvotes: 1
Reputation: 28962
Use the static method [NSBundle mainBundle]
to get an object that represents your application bundle. With this you can then call the instance method - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension
to get a path to the image you have stored. Once you have the path, you can create an instance of UIImage with the image path. You can then create a UIImageView (which could be done in interface builder if you wish), of which you can then set the image to your instance of UIImage.
For example:
NSString* pathToImage = [[NSBundle mainBundle] pathForResource:@"pictureOfJohn" ofType:@"png"];
UIImage* image = [UIImage imageWithContentsOfFile:pathToImage];
UIImageView* imageView = [[UIImageView alloc] init];
imageView.image = image;
[myEnclosingView addSubview:imageView];
[imageView release];
Note that the creation and adding of the imageView could be done in interface builder.
Upvotes: 1