View Single Post
  #3 (permalink)  
Old July 10th, 2013, 09:27 PM
Karl Karl is offline
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