Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: iPhone and iPad App 24-Hour Trainer
This is the forum to discuss the Wrox book iPhone and iPad App 24-Hour Trainer Abhishek Mishra, Gene Backlin; ISBN: 978-1-1181-3081-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: iPhone and iPad App 24-Hour Trainer 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 Display Modes
  #1 (permalink)  
Old June 23rd, 2013, 09:09 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: Queensland
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 6 Errors

Hello there,

I am new to programming and I'm getting on well with your book. I do find that there are some things which appear in the videos and downloaded code which differ greatly from what appears in my X Code. I put it down to differing versions of your XCode and mine. Sometimes I implement what XCode says I should do to correct the errors and sometimes I don't. I've got away with it so far, but now I'm stuck.

My Lesson6ViewController.h looks the same as yours,

My Lesson6ViewController.m has 8 errors and there is a lot of extra code in both the video and the downloaded example. Can you help, I would really appreciate your advice.
Here's the offending code, below.
Thanks, Karl.

OSX 10.7.5, XCode 4.6.3 (4H1503)

--------------------------------------------------------------------------
Code:
Lesson6ViewController.m

    NSString* username = usernameField.text;     ---Error "Use of  undeclared identifier 'usernameField'---                                                     
    
    int length = [username length];                  ---Error "Initializer element is not a compile-time constant---
    if (length == 0)                              ---Error "Expected identifier or'(' "---
        return;
        
    NSString* alertMessage = [NSString stringWithFormat:@"Welcome %@",     ---Error "Initializer element is not a compile-time constant---
                              username];
    
        UIAlertView* welcomeMessage = [[UIAlertView alloc]    ---Error "Initializer element is not a compile-time constant----
                                       initWithTitle:@"Login Successful"
                                       message:alertMessage
                                       delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];

[welcomeMessage show];                               ---Error "Missing '[' at start of message send expression (3)"---

- (void) handleBackgroundTap:(UITapGestureRecognizer *)sender
{
    [usernameField resignFirstResponder];
}
                                
@end
 --------------------------------------------------------------------------
Lesson6ViewController.h

#import <UIKit/UIKit.h>

@interface Lesson6ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)onDismissKeyboard:(id)sender;
- (IBAction)onLogin:(id)sender;
- (void) handleBackgroundTap:(UITapGestureRecognizer*)sender;

@end
--------------------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old June 30th, 2013, 02:23 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

Can you put the entire .h and .m file for your ViewController in a reply? The error is most likely above what you have pasted from the .m file.

Bob
Reply With Quote
  #3 (permalink)  
Old July 10th, 2013, 10:27 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: Queensland
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Lesson 6 My Errors

Hello Bob, thanks for replying,

Here's my .h
Code:
#import <UIKit/UIKit.h>

@interface Lesson6ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)onDismissKeyboard:(id)sender;
- (IBAction)onLogin:(id)sender;
- (void) handleBackgroundTap:(UITapGestureRecognizer*)sender;

@end
And here's my .m
Code:
#import "Lesson6ViewController.h"

@interface Lesson6ViewController ()




@end
@implementation Lesson6ViewController
@synthesize usernameField;
@synthesize passwordField;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self
                                             action:@selector(handleBackgroundTap:)];
    tapRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapRecognizer];
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onDismissKeyboard:(id)sender {
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];

}

- (IBAction)onLogin:(id)sender {
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];
}
    
    NSString* username = usernameField.text;
    
    int length = [username length];
    if (length == 0)
        return;
        
    NSString* alertMessage = [NSString stringWithFormat:@"Welcome %@",
                              username];
    
        UIAlertView* welcomeMessage = [[UIAlertView alloc]
                                       initWithTitle:@"Login Successful"
                                       message:alertMessage
                                       delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];

[[welcomeMessage show]];
 

- (void) handleBackgroundTap:(UITapGestureRecognizer *)sender
{
    [usernameField resignFirstResponder];
}

@end
Thanks for the help, I appreciate it.
Karl
Reply With Quote
  #4 (permalink)  
Old July 11th, 2013, 10:24 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

There are a couple of corrections that should solve your problems.

Code:
- (IBAction)onLogin:(id)sender {
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];
} This curly brace should not be here. There following lines are part of the same method, up to and including [welcomeMessage show];
    
    NSString* username = usernameField.text;
    
    int length = [username length];
    if (length == 0)
        return;
        
    NSString* alertMessage = [NSString stringWithFormat:@"Welcome %@",
                              username];
    
        UIAlertView* welcomeMessage = [[UIAlertView alloc]
                                       initWithTitle:@"Login Successful"
                                       message:alertMessage
                                       delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];

[[welcomeMessage show]]; There should only be one bracket on either side of the message [welcomeMessage show];, not the double that is there.
 This is the point where you should add your closing curly brace}

- (void) handleBackgroundTap:(UITapGestureRecognizer *)sender
{
    [usernameField resignFirstResponder];
}
Here is the correct version in case what I wrote is not clear

Code:
#import "Lesson6ViewController.h"

@interface Lesson6ViewController ()




@end
@implementation Lesson6ViewController
@synthesize usernameField;
@synthesize passwordField;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self
                                             action:@selector(handleBackgroundTap:)];
    tapRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapRecognizer];
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onDismissKeyboard:(id)sender {
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];
    
}

- (IBAction)onLogin:(id)sender {
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];


NSString* username = usernameField.text;

int length = [username length];
if (length == 0)
return;

NSString* alertMessage = [NSString stringWithFormat:@"Welcome %@",
                          username];

UIAlertView* welcomeMessage = [[UIAlertView alloc]
                               initWithTitle:@"Login Successful"
                               message:alertMessage
                               delegate:nil
                               cancelButtonTitle:@"OK"
                               otherButtonTitles:nil];

[welcomeMessage show];

}
- (void) handleBackgroundTap:(UITapGestureRecognizer *)sender
{
    [usernameField resignFirstResponder];
}

@end
The misplaced curly brace } is the root cause of your error messages. You will notice symptoms of syntax errors when autocomplete starts suggesting unusual choices and indentation stops formatting correctly.
Having the double bracket around [[welcomeMessage show]] implies that the result of the first message (inside bracket pair) is receiving another message. There is no another message. You can see how this is used in the various [[SomeObject alloc] init] statements that appear in the program. e.g. the UIAlertView.

Making these corrections should solve your problems, assuming everything is properly connected in the Storyboard. If not, let me know.

The additional code that appears in the author's download version and the book are stub methods, some of which are obsolete in iOS 6, and others that are rarely implemented. The use of ARC has made most memory management automatic. For example -viewDidUnload is never called in iOS 6, and weak pointers (IBOutlets that are weak pointers for example) are automatically set to nil when the view that owns them is deallocated. Under earlier versions, you were responsible for releasing the memory and making everything safe by setting to nil. Useful discussions can be found on StackExchange, and helpful tutorials on Ray Wenderlich's site.



Good luck.


Bob
Reply With Quote
The Following User Says Thank You to thepianoguy For This Useful Post:
Karl (July 14th, 2013)
  #5 (permalink)  
Old July 14th, 2013, 06:16 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: Queensland
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks Bob

Thanks Bob, that got rid of all the errors, my code is the same as yours. However the keyboard does not dismiss. When the Login button is pressed it highlights, but the alert view message does not appear.
I have compared the outlets from the text fields and the button in the connections inspector and everything seems correct. It probably isn't.

I also have a problem with a 3 component UIPicker project. The picker performs correctly, but I cannot get the the the rows to output to a label in anyway. I have tried many different ways and code from the internet, but I suspect it is the connections doing the damage.
I wish I could use the debugger.

Any thoughts?
Karl
Reply With Quote
  #6 (permalink)  
Old July 14th, 2013, 09:53 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

If the problem is in the outlet connections, I would be able to troubleshoot more effectively if I have the actual project. Feel free to send the 2 projects to ipadhelper@me.com
or place them on a file share where I can have access to them and I will take a look.

Bob
Reply With Quote
  #7 (permalink)  
Old July 23rd, 2013, 12:41 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: Queensland
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Fixed them Thanks

Hello Bob,
Thanks for the info. I redid Lesson 6 from scratch, keeping careful eye on what you said and it works well. I also managed to clear up my other project by modifying the UIAlertview output from Lesson 9 to go to my label.
I just have to integrate Facebook and Twitter next.
Once again, thanks for your help.

Karl
Reply With Quote
Reply


Thread Tools
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 3 errors bradut Book: Beginning iOS Application Development with HTML and JavaScript 0 November 23rd, 2012 07:06 PM
Chapter 7 errors janilane BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 May 5th, 2009 04:49 AM
More Errors in chapter 7..... rollercoaster BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 October 3rd, 2006 04:49 PM
Chapter 6 Try It Out errors Voltron ASP.NET 2.0 Basics 0 August 9th, 2006 02:42 AM
Chapter 4 Errors? DRAYKKO BOOK: Beginning Java 2 3 June 1st, 2004 08:47 AM



All times are GMT -4. The time now is 09:59 AM.


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