Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 5 Application Development
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2012, 01:44 PM
Registered User
Points: 40, Level: 1
Points: 40, Level: 1 Points: 40, Level: 1 Points: 40, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
Reply With Quote
  #2 (permalink)  
Old March 8th, 2012, 03:17 PM
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

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
Reply With Quote
  #3 (permalink)  
Old March 8th, 2012, 04:01 PM
Registered User
Points: 40, Level: 1
Points: 40, Level: 1 Points: 40, Level: 1 Points: 40, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by thepianoguy View Post
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?
Reply With Quote
  #4 (permalink)  
Old March 8th, 2012, 11:05 PM
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

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
Reply With Quote
  #5 (permalink)  
Old March 9th, 2012, 02:58 AM
Registered User
Points: 40, Level: 1
Points: 40, Level: 1 Points: 40, Level: 1 Points: 40, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default A better guide book

Would you recommend me a good book that adopts the latest concept for iOS5 for a newbie like me?
Reply With Quote
  #6 (permalink)  
Old March 9th, 2012, 09:04 AM
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

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
Reply With Quote
  #7 (permalink)  
Old March 10th, 2012, 07:35 AM
Registered User
Points: 40, Level: 1
Points: 40, Level: 1 Points: 40, Level: 1 Points: 40, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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'....
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Using Image Views... kenfordboise BOOK: Beginning Android Application Development 19 February 28th, 2012 09:27 AM
Chapter 4 - Switching Views tfiPadn00b BOOK: Beginning iPad Application Development 5 December 20th, 2010 11:01 AM
PG 51 INTERSECT to EXISTS Monchkrit BOOK: Professional Microsoft SQL Server 2008 Programming 0 July 23rd, 2010 09:40 AM
Chapter 4 - Two Views, not working for me... bigtalk BOOK: Beginning Ruby on Rails 1 January 3rd, 2008 07:30 AM



All times are GMT -4. The time now is 07:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.