【问题标题】:How to set cursor to text field when I touch button on AlertView当我触摸 AlertView 上的按钮时如何将光标设置为文本字段
【发布时间】:2015-12-16 11:01:50
【问题描述】:

我有问题需要帮助。 我的问题是:我有 3 个文本字段。目前,光标位于文本字段 (3)。用户可以触摸键盘上的完成按钮。完成按钮后,我检查了格式是否有效。假设,文本字段 2 不是有效的格式类型(显示 uialertview),当我触摸 UIAlertview 上的“确定”按钮时,光标将从文本字段 3 返回到文本字段 2。你能帮我解决问题吗触摸 OK Aleart 视图和将光标从文本字段 3 退回到文本字段 2?

【问题讨论】:

标签: ios


【解决方案1】:

AlertViewOK 按钮处理程序中编写以下代码

 [textField2 becomeFirstResponder];

【讨论】:

    【解决方案2】:
    1. 当您创建 Alertview 时,将代理交给该警报视图的 self。

      YourAlertView.delegate = self;

    2. 添加Alertview的委托处理alert view的按钮事件。

    如果您有多个 Alertview,那么您应该给它们标记并根据标记进行区分。

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == 0)
        {
            [textFiled2 becomeFirstresponder];
        }
    }
    

    【讨论】:

    • 我使用了单元格并创建了 textField2,然后在单元格上重用了它。我在 indexpath 的单元格中初始化它。这是我的代码UITextField *inputTextField = (UITextField *)[cell viewWithTag:2]; switch (indexPath.row) { case 1: inputTextField.keyboardType = UIKeyboardTypeEmailAddress; inputTextField.text = _email; break; default: inputTextField.returnKeyType = UIReturnKeyDone; inputTextField.text = _companyName; break; } [inputTextField becomeFirstResponder];
    • 那么你现在有什么问题?
    • 当我在函数 cellForRowAtIndexPath 中创建文本字段 2 时,如何在 alertView 上调用 textField2
    • 我只想将文本字段放在 alertview 委托中。
    • 想要创建文本域?
    猜你喜欢
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    相关资源
    最近更新 更多