iPhone UITextField with Hide keybord functionality
1.To create UITextField demo project first you can create View-Base application and give name UITextField and valide Company
Identifier and save your project in your directory.
2.Click on UITextFieldViewController.xib put one UIButton from object liberary to cover your screen and set the property type
to custom. and than put two UILabel and UITextField which you can see our Interface Builder given in left image. Now click on
first UITextField and set property in Attribute Inspector keybord sentens or you can keep as default and second UITextField
keybord type Number Pad.
Identifier and save your project in your directory.
2.Click on UITextFieldViewController.xib put one UIButton from object liberary to cover your screen and set the property type
to custom. and than put two UILabel and UITextField which you can see our Interface Builder given in left image. Now click on
first UITextField and set property in Attribute Inspector keybord sentens or you can keep as default and second UITextField
keybord type Number Pad.
3.If you have completed designing of Interface Builder moving further and open your UITextFieldViewController.h file for
defining IBOutlet for UITextField and IBAction for hiding keybord.
#import <UIKit/UIKit.h>
@interface TextFieldViewController : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField * numberField;
}
@property(nonatomic,retain)UITextField * numberField;
-(IBAction)textFieldDone:(id)sender;
-(IBAction)numberFieldDone:(id)sender;
@end
4.After defining IBOutlet and IBAction open UITextFieldViewController.xib file and see the Connectivity Inspector and set second
UITextField to numberField IBOutlet to click on small round given in IBOutlet and put on number text field. Now set IBAction
textFieldDone to first UITextField and select Did End Editing action and second IBAction numberFieldDone to UIButton and
select action Touch Up Inside.
5.Now modify your UITextFieldViewController.m file. First synthesize your property and implements both method.
#import "TextFieldViewController.h"
@implementation TextFieldViewController
@synthesize numberField;
-(IBAction)textFieldDone:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)numberFieldDone:(id)sender
{
[numberField resignFirstResponder];
}
- (void)dealloc
{
[numberField release];
[super dealloc];
}
@end
6. Now click build and Go your project run in simulator when first text field should done editing then press return key of keybord
for hiding keybord and second text field should done editing Number pad keybord can not have return key thats way we can
not hide keybord by using return key you can click on background of your interface buider your keybord hiding action will be
occurs.
defining IBOutlet for UITextField and IBAction for hiding keybord.
#import <UIKit/UIKit.h>
@interface TextFieldViewController : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField * numberField;
}
@property(nonatomic,retain)UITextField * numberField;
-(IBAction)textFieldDone:(id)sender;
-(IBAction)numberFieldDone:(id)sender;
@end
4.After defining IBOutlet and IBAction open UITextFieldViewController.xib file and see the Connectivity Inspector and set second
UITextField to numberField IBOutlet to click on small round given in IBOutlet and put on number text field. Now set IBAction
textFieldDone to first UITextField and select Did End Editing action and second IBAction numberFieldDone to UIButton and
select action Touch Up Inside.
5.Now modify your UITextFieldViewController.m file. First synthesize your property and implements both method.
#import "TextFieldViewController.h"
@implementation TextFieldViewController
@synthesize numberField;
-(IBAction)textFieldDone:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)numberFieldDone:(id)sender
{
[numberField resignFirstResponder];
}
- (void)dealloc
{
[numberField release];
[super dealloc];
}
@end
6. Now click build and Go your project run in simulator when first text field should done editing then press return key of keybord
for hiding keybord and second text field should done editing Number pad keybord can not have return key thats way we can
not hide keybord by using return key you can click on background of your interface buider your keybord hiding action will be
occurs.
Related Posts :
1. Animation like a toggle button in iphone
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. UISegmented control in iPhone with value change event
5. Create simple UINavigation controller in iPhone
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. UISegmented control in iPhone with value change event
5. Create simple UINavigation controller in iPhone
HTML Comment Box is loading comments...