I just started playing around with XCode a few hours ago, doing the HelloWorld tutorial.
I managed to close the keyboard window when the user clicks the Return button.
However, my button should have the exact same behavior as the Return button. It does the same right now, it just doens’t close down the keyboard upon submission. How can i do this?
- (IBAction)button:(id)sender {
[self changeLabelWithText: self.textField.text];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textField) {
[theTextField resignFirstResponder];
[self changeLabelWithText: self.label.text];
}
return YES;
}
- (void)changeLabelWithText: (NSString *) text {
self.label.text = [NSString stringWithFormat:@"Hej, %@", text];
}
Try this,
[textFieldName resignFirstResponder];