文本字段不会成为第一响应者

问题描述 投票:1回答:1

我似乎处于一种情况,其中调用BeginFirstResponder()不能按预期方式工作。

说我在视图中有两个文本框。第一个文本框是ViewDidLoad()的第一个响应者;

单击按钮,我希望第二个文本框成为第一响应者。

问题是,如果我使用以下几行启动对话框,

var alertView = UIAlertController.Create("Title", "Message", UIAlertControllerStyle.Alert);
alertView.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;

var negativeAction = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null);
alertView.AddAction(negativeAction);

//if (!string.IsNullOrWhiteSpace(""))
//{
//  var positiveAction = UIAlertAction.Create("", UIAlertActionStyle.Default, null);
//  alertView.AddAction(positiveAction);
//}

PresentViewController(alertView, true, delegate {
    alertView.ResignFirstResponder();
});

然后呼叫tbSecond.BecomeFirstResponder();,第一个响应者无法更改。

如果我使用下面的旧UIAlert类启动对话框,则第一响应者将按预期工作。

var alertView = new UIAlertView("Title", "Message", null, "Cancel", null);
alertView.Show();

然后打电话

tbSecond.BecomeFirstResponder();

如果更改顺序,即调用tbSecond.BecomeFirstResponder(),我将无法更改调用顺序。在我致电ShowDialog之前,它会按预期工作。但是由于种种原因,我无法更改该顺序。

ios uialertcontroller becomefirstresponder
1个回答
0
投票
DispatchQueue.main.asyncAfter(deadline: .now()) { alertController.textFields?.last?.becomeFirstResponder() }
相关问题
热门问答
最新问题