Home Tutorial Iphone Examples AlertViewWithPassWord iPhone

 
 

AlertViewWithPassWord iPhone
Posted on: September 8, 2009 at 12:00 AM
Advertisement
In this tutorial will learn how to show Alert Box when text field is empty and the AlertView is Consist of Two textfield one is for name and another is for Password. The application we are going to do is based on View Based Application.

Iphone AlertView With PassWord

In this tutorial will learn how to show Alert Box when text field is empty and the AlertView is Consist of Two textfield one is for name and another is for Password. The application we are going to do is based on View Based Application.

Final View will look like this:

iphone alertview

My project name is AlertView, is view based Application. To show Alert view when text field is empty will add some codes in .h and .m file and will show Alert view with password, only when the button is clicked and will write Alert View code into the Button Action, so whenever button is clicked will show you Alert box and once Alert View is showed you have to enter the password and then click Conform otherwise you wont be able to enter the text into the text field.
Now to enter text we need TextField and to enter the Password we need text field and also Button to show Alert View and action to button, so will declare it in .h file.

AlertViewPasswordViewController.h file will look like this:

#import <UIKit/UIKit.h>

@interface AlertViewPasswordViewController : UIViewController {

    IBOutlet UITextField *textField;           // for enter text

    IBOutlet UITextField *textfieldPassword;  //textfield for alertview to enter PassWord

}

- (IBAction)showAlertBox:(id)sender;

@end

In .m will write the method for that action and in that will write code for Alert View.In action method will check the length of textfield by using if condition and if textfield is equal to zero then at button click will show alert view and also will ask for password and in that will set the title, message in AlertView with the help of 
UIAlertView *passwordAlert = [[UIAlertView alloc]initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Submit",nil];
this Method and the word you type on it is convert into bots is using 
[passwordAlert addTextFieldWithValue:@"" label:@"Password"];

and the password on alertview is shown with the help of sentence as shown.

UITextField *textfield = [passwordAlert textFieldAtIndex:0];
textfield.secureTextEntry = YES;
[passwordAlert show];

AlertViewPasswordViewController.m file will look like this:

#import "AlertViewPasswordViewController.h"

@implementation AlertViewPasswordViewController

- (IBAction)showAlertBox:(id)sender

{

    UIAlertView *passwordAlert = [[UIAlertView alloc]

                                initWithTitle:@"Enter Password" message:@""

                                delegate:self cancelButtonTitle:nil                    

                                otherButtonTitles:@"Submit",nil];

        [passwordAlert addTextFieldWithValue:@"" label:@"Password"];

    UITextField *textfield = [passwordAlert textFieldAtIndex:0];

    textfield.secureTextEntry = YES;

    [passwordAlert show];

}

- (void)didReceiveMemoryWarning {

   [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {

}

- (void)dealloc {

    [super dealloc];

}

@end

Make connection with Interface Builder as shown :

Finally Press Build And Go Button

Download the Source Code

Advertisement

Related Tags for AlertViewWithPassWord iPhone:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 8, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com