Saturday, August 11, 2012

Text Field General

Text fields are for single line text.  For multi line text use Text View


Keyboard return key pressed

Example Of Use

Declaring in #ViewController.h file
        IBOutlet UITextField *MyTextFieldName;
Releasing in #ViewController.m file
//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
        [super viewDidUnload];

        [MyTextFieldName release];
        MyTextFieldName = nil;

//********** DEALLOC **********
- (void)dealloc
        [MyTextFieldName release];

        [super dealloc];
Connecting in Interface Builder
Add the text filed to the view
Right click Files Owner
Drag the outlet to your text field

Storing Values Entered In A Text Field

        [SomeIntVariable:[[SomeTextField text] intValue]];

Dismissing The Keyboard & Responding To Input

Open the XIB.
For each of the text fields, right click and drag the ‘delegate’ circle to ‘Files Owner’

Then in #ViewController.m:
//********** TEXT FIELD SHOULD RETURN **********
- (BOOL)textFieldShouldReturn:(UITextField *)textField
        [textField resignFirstResponder];
        return YES;
If you have any methods in #ViewController.m that want to ensure the keyboard is removed:
//********** VIEW WILL DISAPPEAR **********
- (void)viewWillDisappear:(BOOL)animated
        [super viewWillDisappear:animated];

        [[self view] endEditing:YES];           //Ensure keyboard is removed

No comments:

Post a Comment