当UIView显示时,让UITextField显示键盘(becomeFirstResponder) [英] Have UITextField show keyboard (becomeFirstResponder) when UIView is shown

查看:245
本文介绍了当UIView显示时,让UITextField显示键盘(becomeFirstResponder)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带UITableView的UIViewController。 UITableView的第一行是一个包含UITextField的单元格。我想通过在显示视图时显示键盘来稍微改善我的UI。我已经尝试将BecomeFirstResponder方法放在各种事件中,但还没有让它工作。

I have a UIViewController with a UITableView. The first row of the UITableView is a cell that has a UITextField in it. I'd like to improve my UI a little by showing the keyboard when the view is shown. I have tried putting the BecomeFirstResponder method in various events but have yet to get this to work.

有人可以提供有关如何在呈现视图时呈现键盘的提示通过PushViewController?

Can someone please provide tips on how to present the keyboard when the view is presented via the PushViewController?

谢谢。

推荐答案

在你的子类中UITableViewSource或UITableViewDelegate尝试重写WillDisplay方法,如下所示:

In your subclass of UITableViewSource or UITableViewDelegate try overriding WillDisplay method, like this:

public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
  if(indexPath.Row == theRowIndexOfTheCellWithYourTextField){
    yourTextField.BecomeFirstResponder();
  }
}

它应该有效(请注意,您可能希望添加一些代码,以确保只执行一次)

It should work (note that you probably wish to add some code to make sure this is executed only once)

这篇关于当UIView显示时,让UITextField显示键盘(becomeFirstResponder)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆