Tuesday, August 6, 2013

iOS Login Apllication

Add following code in .h file


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
    

    IBOutlet UITextField *txtname;
    
    IBOutlet UITextField *txtpassword;
    
}

@property (nonatomic, retain) IBOutlet UITextField *txtname;
@property (nonatomic, retain) IBOutlet UITextField *txtpassword;

-(IBAction) mylogin;

-(IBAction) makeKeyBoardGoAway;

@end




Add following code in .m file

- (IBAction) mylogin
{
    
    if ([txtname.text isEqualToString:duName]  && [txtpassword.text isEqualToString:dpassword])
    {
        
        UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"Suucessfull Logi...."
                                                        message:@"Welcome.!"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitlesnil];
        [alert show];
                            
       }
    
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Fail...."
                                                        message:@"Username OR Password Incorrect.!"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
                
    
    }

}


-(IBAction) makeKeyBoardGoAway{
    
    [txtpassword resignFirstResponder];
}


Aslo want create UI and match the components with File Owner......

How to set "back" button in iOS application



1. Add following method in .m file


-(void)backToMain:(id)sender

{
    ViewController *toHome =[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    [self presentModalViewController:toHome animated:YES];         

}

2. Add following code in .m file  (void)viewDidLoad method



    UINavigationBar *naviBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0,           [UIScreen mainScreen].bounds.size.width, 44)];
    naviBar.delegate = self;
    naviBar.tintColor = [UIColor blueColor];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"  style:UIBarButtonItemStyleBordered target:self action:@selector(backToMain:)];
    
    UINavigationItem *naviItem = [[UINavigationItem alloc] init];
    naviItem.leftBarButtonItem = backItem;
    naviBar.items = [NSArray arrayWithObjects:naviItem, nil];
    [self.view addSubview:naviBar];


1. Add following method in .h file

-(IBAction) backToMain:(id)sender;