[英]textFieldShouldReturn is not working anymore
在iPad上,textFieldShouldReturn不再起作用。 直到大約五分鍾前,我才開始使用它,突然不再調用該方法了……有什么想法嗎? 下面是代碼,唯一改變的是UITextView的通知…謝謝!
- (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;
}
最好的可能性-您可能不小心刪除了文本字段的委托。
在IOS 6中檢查(BOOL)textFieldShouldReturn:(UITextField *)textField
方法。您必須在XIB中設置textField
委托並寫下以下代碼:
(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.