Wrox Programmer Forums
|
BOOK: Professional iPhone and iPad Database Application Programming
This is the forum to discuss the Wrox book Professional iPhone and iPad Database Application Programming by Patrick Alessi; ISBN: 978-0-470-63617-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Database Application Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2011, 06:40 PM
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 3 - Image ProductDetailViewController

How can you load the item image in the ProductDetailViewController?
Thanks
The Following User Says Thank You to nickpsaris For This Useful Post:
Jule (April 2nd, 2012)
 
Old December 22nd, 2011, 10:38 AM
Friend of Wrox
 
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)
 
Old December 27th, 2011, 05:56 PM
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you very much it work!!!!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 - URL for image weimenglee BOOK: Beginning Android Application Development 0 May 5th, 2011 09:27 PM
CHAPTER 7 - UPDATE an Image dutraveller BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 4 March 20th, 2008 12:27 PM
Chapter 7 - Image Problem SoftMind BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 June 19th, 2006 04:30 PM
Chapter 5-Image Mapping Help! maxcain Dreamweaver (all versions) 3 March 16th, 2004 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.