2009-09-21 66 views
0

在我的视图控制器中,我添加了如下的文本字段。键盘不解扣

txt1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 70, 20)]; 
txt1.delegate = self; 
txt1.borderStyle = UITextBorderStyleRoundedRect; 
[self.view addSubview:txt1]; 
[txt1 release]; 

.h文件中设置UITextFieldDelegate。我写

-(BOOL)textFieldShouldReturn:(UITextField *)textField 

解散我的keyboard.But它不解雇委托方法。 任何帮助! 在此先感谢。

回答

1

您是否试过发送resignFirstResponder消息?

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

我在textFieldShouldReturn中发送[textField resignFirstResponder]。但委托方法本身没有触发,而我点击返回按钮。 – diana 2009-09-21 10:11:37

+0

我在AppllicationDelegate中做了同样的事情。在这里,我在窗口中添加了文本框。这是工作。这背后的原因是什么?任何想法? – diana 2009-09-21 10:14:16

+0

你需要发布整个代码。 – arul 2009-09-21 11:03:15