【问题标题】:Button as a Return Key按钮作为返回键
【发布时间】:2015-11-11 01:16:22
【问题描述】:

我有一个文本字段和一个按钮。在文本位于文本字段内而不是按回车后,我可以点击我的文本字段附近的按钮,它的作用就像“回车”或“回车”键。

我找到了一个 stackoverflow anwser,有点像我的问题:但仍然无法正常工作“How to click UIButton when user hits return on keyboard

我只需要按钮像“Enter”或“Return”按钮一样工作。

【问题讨论】:

    标签: ios button action textfield enter


    【解决方案1】:
    @IBAction returnButton(sender: UiButton) {
        textFieldNextToButton.resignFirstResponder()
    }
    

    更新:在 OBJ-C 中

    (IBAction)Button1:(id) sender {
        [currentTextField resignFirstResponder];
    }
    

    【讨论】:

    • 我应该把这段代码放在哪里?我现在试图把它放在哪里,都会说“程序中出现意外的'@”。
    • 您从 Storyboard 中的按钮(假设您正在使用 Storyboard)按住 ctrl 并拖动到 ViewController 中的任何位置(但不在函数内部)。它为您创建@IBAction。或者,如果您已经通过按钮运行了代码,请将 textField.resignFirstResponder() 放入该函数中。
    • 在 IBAction stackoverflow.com/questions/32572305/…987654321@ 上查看更多信息
    • 我为按钮创建了一个“IBAction”。这段代码也是创建的“ -(IBAction)Button1:(id) sender {}
    • 所以我将代码“textFieldNextToButton.resignFirstResponder()”放入 IBAction 代码中。但我收到错误:“未使用属性访问结果 - getter 不应用于副作用”
    猜你喜欢
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    相关资源
    最近更新 更多