View Single Post
  #2 (permalink)  
Old December 22nd, 2011, 10:38 AM
thepianoguy thepianoguy is offline
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Assuming I understand your question right, you want the image that is on the left in the tableCell of the rootViewController to also appear in the ProductDetailView. Two options that are available are:
1. add a UIImageView to the ProductDetailViewController.xib and as an IBOutlet in the ProductDetailViewController.h. (additions are bold)
@interface ProductDetailViewController : UIViewController {


IBOutlet UILabel* nameLabel;
IBOutlet UILabel* manufacturerLabel;
IBOutlet UILabel* detailsLabel;
IBOutlet UILabel* priceLabel;
IBOutlet UILabel* quantityLabel;
IBOutlet UILabel* countryLabel;
IBOutlet UIImageView *productImage;


}
Make the connection. In the ProductDetailViewController.m add the following (additions are bold)

-(void) setLabelsForProduct: (Product*) theProduct
{
// Set the text of the labels to the values passed in the Product object
[nameLabel setText:theProduct.name];
[manufacturerLabel setText:theProduct.manufacturer];
[detailsLabel setText:theProduct.details];
[priceLabel setText:[NSString stringWithFormat:@"%.2f",theProduct.price]];
[quantityLabel setText:[NSString stringWithFormat:@"%d",theProduct.quantity]];
[countryLabel setText:theProduct.countryOfOrigin];
NSString *filePath = [[NSBundle mainBundle] pathForResource:theProduct.image ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
productImage.image = image;

}
and option 2 would entail adding the UIImageView in code as a subview of the ProductDetailController.view rather than in the .xib and as an IBOutlet

2. In the ProductDetailViewController.m add the following (additions are bold)


-(void) setLabelsForProduct: (Product*) theProduct
{
// Set the text of the labels to the values passed in the Product object
[nameLabel setText:theProduct.name];
[manufacturerLabel setText:theProduct.manufacturer];
[detailsLabel setText:theProduct.details];
[priceLabel setText:[NSString stringWithFormat:@"%.2f",theProduct.price]];
[quantityLabel setText:[NSString stringWithFormat:@"%d",theProduct.quantity]];
[countryLabel setText:theProduct.countryOfOrigin];
UIImageView *prodImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 20, 100, 100)];
[self.view addSubview:prodImage];
NSString *filePath = [[NSBundle mainBundle] pathForResource:theProduct.image ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
prodImage.image = image;
[prodImage release];

}

Since the original project is "pre ARC" the retain/release pattern is used.
Hope this helps.

Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
Jule (April 2nd, 2012)