textFieldShouldReturn is not working anymore
On iPad, textFieldShouldReturn is not work开发者_如何转开发ing anymore. I had it working until like five minutes ago, suddenly the method is not called anymore … Any Ideas? Below is the code, the only thing changed was a notification for an UITextView… Thanks!
- (BOOL)textFieldShouldReturn:(UITextField *)tf
{
NSString* newName = textField.text;
textLabel.text = textField.text;
NSLog(@"Called!");
newName = [newName stringByAppendingPathExtension:@"txt"];
NSString* newPath = [[currentFilePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
NSLog(@"%@",newPath);
[[NSFileManager defaultManager] moveItemAtPath:currentFilePath toPath:newPath error:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"DataSaved" object:nil];
[currentFilePath retain];
currentFilePath = newPath;
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
[currentFilePath retain];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil]);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
textLabel.alpha = 1.0;
textField.alpha = 0.0;
[UIView commitAnimations];
[tf resignFirstResponder];
return YES;
}
best possibility - you might have accidentally removed the delegate for the textfield.
Check for (BOOL)textFieldShouldReturn:(UITextField *)textField
method in IOS 6. You have to set the textField
delegate in XIB and write down the following code:
(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
精彩评论