MonoTouch for iPhone:如何制作UIButton焦点?

时间:2011-10-30 16:21:23

标签: xamarin.ios uitextfield

我在视图上有两个UITextField和一个按钮。我希望用户能够使用tab或return键遍历三个控件。但是,我只能让它们循环遍历TextFields。这是我在ViewDidLoad()中的代码:

    public override void ViewDidLoad()
    {
        tfFirstName.BecomeFirstResponder();
        tfFirstName.ShouldReturn = delegate
        {
            tfLastName.BecomeFirstResponder(); // move focus to LastName field
            return true;
        };
        tfLastName.ShouldReturn = delegate
        {
            btnOK.BecomeFirstResponder(); // move focus to OK button
            btnOK.ResignFirstResponder(); // hide the keyboard
            return true;
        };
    }

在IB中,我还将两个文本字段的“返回键”更改为“下一步”。

在我看来,tfFirstName.ShouldReturn代表有效,但tfLastName.ShouldReturn不起作用。为什么呢?

1 个答案:

答案 0 :(得分:1)

基于触摸的应用程序实际上没有像基于鼠标/键盘的应用程序那样“聚焦”的概念。将“焦点”分配给不接受键盘输入的控件(如按钮)是没有意义的。

相关问题