2011-09-22 140 views
0

在iPad上,textFieldShouldReturn不再工作。我有它的工作,直到五分鐘前,突然沒有調用方法...任何想法?下面是代碼,唯一改變的是UITextView的通知......謝謝!textFieldShouldReturn不再工作

- (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; 

}

+1

最好的可能性 - 你可能會不小心刪除了文本框的委託。 – samfisher

+0

好吧,你是對的。如果你可以添加它作爲答案,以便我可以接受它作爲答案會很好;)非常感謝!創造了我的一天。 – Faser

+0

我很高興..我可以幫助..! – samfisher

回答

5

最好的可能性 - 你可能會不小心刪除的文本框的委託。

3

您在IOS 6 (BOOL)textFieldShouldReturn:(UITextField *)textField方法必須設置在廈門國際銀行的textField委託,並寫下了下面的代碼:

(BOOL)textFieldShouldReturn:(UITextField *)textField{ 
    [textField resignFirstResponder]; 
    return YES; 
}