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