By Rupert
iPhone Note #17: Displaying a custom view controller from a UITextField
Problem: I want my textFieldSearchAddress to display a seperate viewcontroller.

Short Answer: Hide the keyboard by using
[textField resignFirstResponder]
then show the view controller.
1. Implement a UITextFieldDelegate.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ [textField resignFirstResponder]; [self show]; return NO; }
Be careful with the BOOL return of textFieldShouldBeginEditing. From the docs: “YES if an editing session should be initiated; otherwise, NO to disallow editing.”
2. Show the view controller.
- (IBAction)show{ NSLog(@"show"); AddressViewController *addressViewController = [[AddressViewController alloc] initWithNibName:@"AddressViewController" bundle:nil]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:addressViewController]; [self presentModalViewController:nav animated:YES]; [addressViewController release]; [nav release]; }
| Print article | This entry was posted by rupert on November 2, 2009 at 11:49 am, and is filed under iphone. Follow any responses to this post through RSS 2.0. You can skip to the end and leave a response. Pinging is currently not allowed. |


