I'm new to iOS development and am currently studying from video tutorials. I came across a problem with quite a simple app I'm experimenting on.
The problem is with loading pictures to UIImage
in a split view control iPad app. The app is based on the XCode master-detail application template. I created an array with NSObject
variables and two properties.
@interface Burger : NSObject
@property (nonatomic) NSString *name;
@property (nonatomic) NSString *filename;
@end
- (void)viewDidLoad {
[super viewDidLoad];
photos = [[NSMutableArray alloc]init];
Burger *pic = [[Burger alloc]init];
pic.name = @"Bacon";
pic.filename = @"burger-bacon";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Cheese";
pic.filename = @"burger-cheddar";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Hawaii";
pic.filename = @"burger-hawaii";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Koko z jajkiej kurzym";
pic.filename = @"burger-jajo";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Kozi ser";
pic.filename = @"burger-kozi";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Łosoś";
pic.filename = @"burger-losos";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = @"Vege (Soczewica)";
pic.filename = @"burger-soczewica";
[photos addObject:pic];
}
I want the UImageView
nested in DetailView
to display a picture of the object chosen in the MasterView
controller. I got it to display the pictures in the MasterView
table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Burger *current = [photos objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:[current filename]];
[cell.imageView setImage:image];
self.title = self.currentPhoto.name;
cell.textLabel.text = [current name];
cell.detailTextLabel.text = [current price];
return cell;
}
and it also works when I point to a specific file name:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: @"burger-bacon"];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
but when I try to show the picture of the chosen element like this:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: self.currentPhoto.filename];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
I get these few lines in the debug area:
2015-06-23 12:13:25.964 SlowFoodiPad[22177:744765] CUICatalog: Invalid asset name supplied: (null)
which means the segues work and the photo files seem to be fine. There seem to be a problem with pointing to the right file to display. Any ideas how to fix it?
OK, I managed to solve the problem partially. I edited prepareForSegue method of MasterViewController:
The appropriate photos now show, although the debug area keeps showing me this message:
two identical lines each time I tap on an element in the MasterView table.