我希望键盘在出现某个UITextView
时自动显示。现在,第一次UITextView
出现时,用户必须点击它才能显示键盘。随后出现的UITextView
会自动显示键盘。如何在UITextView
第一次出现时才能实现这一目标?
-(void)displayComposeScreen
{
[self.nameField resignFirstResponder]; //This is a different UITextView, but my issue doesn't change whether I leave this line in or take it out
if (!self.textView)
{
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 280, 150)]; //This is the UITextView with whose appearance I want the keyboard to appear automatically.
self.textView.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
self.textView.delegate = self;
}
[self.textView becomeFirstResponder];
self.textView.hidden=NO;
if (self.ghhaiku.userIsEditing==NO)
{
self.textView.text = @"";
}
else
{
self.textView.text = self.ghhaiku.text;
}
[self.view addSubview:self.textView];
}
基本上,第一次调用此方法时,用户必须点击self.textView
才能显示键盘,并且我希望键盘在调用方法时自动显示,就像在后续调用时一样这种方法。
答案 0 :(得分:3)
您应该输入代码
[self.textView becomeFirstResponder]
在之后,您已将文本视图放入控制器的视图中。
答案 1 :(得分:2)
希望能帮到你
[textField performSelector:@selector(becomeFirstResponder)
withObject:nil
afterDelay:0.2f]
In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear:(对https://stackoverflow.com/users/1162777/anton提问题的评论)
答案 2 :(得分:0)
如果要激活textView,请尝试以下行。
[self.textView becomeFirstResponder];
答案 3 :(得分:-1)
[UIView animateWithDuration:0.0 animations:^{
[self addSubview:textview];
} completion:^(BOOL finished){
[textview becomeFirstResponder];
}];