 |
BOOK: Beginning iOS 5 Application Development
 | This is the forum to discuss the Wrox book Beginning iOS 5 Application Development by Wei-Meng Lee; ISBN: 978-1-1181-4425-1 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning iOS 5 Application Development 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
|
|
|

March 8th, 2012, 01:44 PM
|
Registered User
|
|
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 3 - Using Views, PG 51
Hi guys, i'm a newbie so i hope y'all can forgive me if i sound stupid.
I'm trying out the code reflected on chapter 3 - Using Views on PG 51 of the book.
I decided to use my own graphics; sample1.jpg, sample2.jpg, sample3.jpg, sample4.jpg and sample5.jpg. I followed the instruction on dragging the graphics into the "Supporting Files" folder as described on page 47 and rename the files in the codes to the filenames i am using. Below are the errors i encountered.
Code:
//////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad
{
// initialise the first imageview to display an image
[imageView1 setImage:[UIImageView imageNamed:@"sample1.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
tempImageView = imageView2;
//make the first imageView visible and the second imageView invisible
[imageView1 setHidden:NO];
[imageView2 setHidden:YES];
//add event handler for page control
[pageControl addTarget:self
action:@selector(pageTurning:)
forControlEvents:UIControlEventValueChanged];
prevPage = 0; error: Semantic Issue: Use of undeclared identifier 'prevPage'
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// when page control value is changed
- (void) pageTurning: (UIPageControl *) pageController{
//get page number you can turn to
NSInteger nextPage = [pageController currentPage];
switch (nextPage) {
case 0:
[tempImageView setImage:[UIImageView imageNamed:@"sample1.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
break;
case 1:
[tempImageView setImage:[UIImageView imageNamed:@"sample2.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
break;
case 2:
[tempImageView setImage:[UIImageView imageNamed:@"sample3.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
break;
case 3:
[tempImageView setImage:[UIImageView imageNamed:@"sample4.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
break;
case 4:
[tempImageView setImage:[UIImageView imageNamed:@"sample5.jpg"]];Class method '+imageNamed:' not found (return type defaults to 'id')
break;
default:
break;
}
//switch the two imageView views
if (tempImageView.tag == 0) {
tempImageView = imageView2;
bgImageView = imageView1;
}
else{
tempImageView = imageView1;
bgImageView = imageView2;
}
UIViewAnimationOptions transitionOption;
if (nextPage > prevPage) {
transitionOption = UIViewAnimationOptionTransitionFlipFromLeft;
}
else{
transitionOption = UIViewAnimationOptionTransitionFlipFromRight;
}
// animate by flipping the pages
[UIView transitionWithView:tempImageView
duration:2.5
options:transitionOption
animations:^{
[tempImageView setHidden:YES];
}
completion:NULL];
[UIView transitionWithView:bgImageView
duration:2.5
options:transitionOption
animations:^{
[bgImageView setHidden:NO];
}
completion:NULL];
}
- (void) dealloc{
[pageControl release];
[imageView1 release];
[imageView2 release];
[super dealloc];
}
//////////////////////////////////////////////////////////////////////////////////////////
Thanx in advance...
|

March 8th, 2012, 03:17 PM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
UIImageView does not have a method "imageNamed:". UIImage does.
[imageView1 setImage:[UIImage imageNamed:@"sample1.jpg"]]; is correct
All subsequent lines with this error have the same problem.
is "prevPage" in your header file? It should be declared as an int or NSUInteger either in your .h file or in an anonymous category in your .m file. If it is not declared the compiler has not idea as to what it is.
Bob
|

March 8th, 2012, 04:01 PM
|
Registered User
|
|
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by thepianoguy
UIImageView does not have a method "imageNamed:". UIImage does.
[imageView1 setImage:[UIImage imageNamed:@"sample1.jpg"]]; is correct
All subsequent lines with this error have the same problem.
is "prevPage" in your header file? It should be declared as an int or NSUInteger either in your .h file or in an anonymous category in your .m file. If it is not declared the compiler has not idea as to what it is.
Bob
|
I'm following exactly what the book says. If that is the case can you please guide me the syntax to declare the variable 'prevPage'. Should i declare it in .h or .m of the project?
|

March 8th, 2012, 11:05 PM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
Whether you declare it in the .h or .m file is a matter of personal preference. I don't have this book, but from the downloaded source code the author places it in the .h file.
Code:
#import <UIKit/UIKit.h>
@interface UsingViewsViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate>
{
IBOutlet UIPageControl *pageControl;
IBOutlet UIImageView *imageView1;
IBOutlet UIImageView *imageView2;
UIImageView *tempImageView, *bgImageView;
int prevPage;
}
@property (nonatomic, retain) UIPageControl *pageControl;
@property (nonatomic, retain) UIImageView *imageView1;
@property (nonatomic, retain) UIImageView *imageView2;
@end
There has been substantial evolution in coding style in Objective-C and Xcode over the past couple of years, and this book is using an older approach. Since prevPage is only used inside the class it does not need to (and in some people's opinions shouldn't) be exposed in the header. iVars in the .h should be @properties that other files might need to know about, not private variables that are simply for implementation usage. So, while the author's approach is perfectly valid, the following is more current:
The .h file
Code:
#import <UIKit/UIKit.h>
@interface UsingViewsViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate>
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
@property (nonatomic, retain) IBOutlet UIImageView *imageView1;
@property (nonatomic, retain) IBOutlet UIImageView *imageView2;
@end
with the IBOutlets declared as @properties
The .m file
Code:
#import "UsingViewsViewController.h"
@implementation UsingViewsViewController
{
UIImageView *tempImageView, *bgImageView;
int prevPage;
}
@synthesize pageControl;
@synthesize imageView1, imageView2;
- (void)viewDidLoad
etc.
or as an anonymous category (class extension)
in the .m
Code:
#import "UsingViewsViewController.h"
@interface UsingViewsViewController ()
{
UIImageView *tempImageView, *bgImageView;
int prevPage;
}
@end
@implementation UsingViewsViewController
@synthesize pageControl;
@synthesize imageView1, imageView2;
- (void)viewDidLoad
etc.
Bob
|

March 9th, 2012, 02:58 AM
|
Registered User
|
|
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
A better guide book
Would you recommend me a good book that adopts the latest concept for iOS5 for a newbie like me?
|

March 9th, 2012, 09:04 AM
|
Friend of Wrox
|
|
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
|
|
I don't think suggesting other iOS 5 books in this forum would be appropriate. However, if you don't have much background in C or Objective-C, (which I suspect, due to the original question), I strongly recommend that you strengthen your background in that area first. An excellent Objective-C book is Stephen Kochan's "Programming in Objective-C 4th edition". It is not an iOS book but covers Xcode 4, Objective-C and object-oriented concepts, and the Foundation framework. It does end with an iOS project. It also has an active forum that the author participates in. The author here has published quite a number of books, but rarely contributes responses in the forum.
Attempting to do iOS programming without a good Objective-C background is potentially very frustrating. Simple typos, copy and syntax errors will not be as obvious, and the focus, which should be on learning to use the frameworks, will be deflected. The Kochan book, if used correctly (i.e. treat it like going to class every day; do all the exercises), can be completed in about 2 months. It will be a valuable and ultimately time saving detour. You don't want to complete this book and find that all you can do is copy code.
At that point, or even concurrently, you could continue on with this book.
A good source for evaluating iOS 5 books is the reviews on Amazon. Readers who have been disappointed in the contents of books being current are usually quite vocal (in the iOS 5 case - Does the book cover ARC, storyboarding for example).
For what it is worth,
Bob
|

March 10th, 2012, 07:35 AM
|
Registered User
|
|
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx...
I am very serious about picking up this skill set. My experience is mainly on PHP. I have ordered the book from amazon and its expected to arrive April 14. In the meantime i have no choice but to rely on whatever resources i currently have.
I understand that ur very busy but i do hope that you could assist, if you have the time, when i post my queries. Thanx again the 'thepianoguy'....
|
|
 |
|