pp105
property
- (void)Done
{
NSLog(@"Contents of the text field: %@",self.textField.text);
//close the window
[self.presentingViewControllerdismissViewControllerAnimated:YEScompletion:nil];
}
//The view controller receives veiwWillAppear just before it becomes visible
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//The control becomes the first responder let the keyboard pop up automatically
[self.textFieldbecomeFirstResponder];
}
Disable Done key In key board if no entering words in text view pp112
PP114 Disable Done key in bar button when no input in the text field
//This is one of the UITextField delegate method, it is invoked every time the user changes text, whether by tapping on the keyboard or cut/paste
- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//Figure out what the real text it would be
NSString *newText = [theTextField.textstringByReplacingCharactersInRange:range withString:string];
if ([newText length] >0) {
self.doneBarButton.enabled =YES;
} else {
self.doneBarButton.enabled =NO;
}
return YES;
}
![](https://img-my.csdn.net/uploads/201303/06/1362546194_9916.png)