ios 点击 UITextField 时未出现 UIKeyboard

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23342345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:02:18  来源:igfitidea点击:

UIKeyboard not appearing when tapping on UITextField

iosxcodeswiftuitextfield

提问by Shekhu

This is the Signup VC ,as Tapping pops the white space Not the KeyBoardThis is the login VC ,as Tapping pops the white space Not the KeyBoard

这是注册 VC,因为 Tapping 弹出空白而不是键盘这是登录 VC,因为 Tapping 弹出空白而不是键盘

I had been into a weird problem, As every other thing is working fine. All of sudden when I compile my application and got this problem, when I tapped on the UITextFieldwhite space is popping up, but the keyboard is not visible and I am not able to enter anything.

我遇到了一个奇怪的问题,因为其他一切都正常。突然当我编译我的应用程序并遇到这个问题时,当我点击UITextField空白区域时会弹出,但键盘不可见,我无法输入任何内容。

回答by Shekhu

Following will fix the keyboard issue

以下将解决键盘问题

Simulator -> Hardware -> Keyboard -> Toggle Software Keyboardshould solve this problem.

Simulator -> Hardware -> Keyboard -> Toggle Software Keyboard应该可以解决这个问题。

![Simulator->Hardware->Keyboard->Toggle Software Keyboard]

![模拟器->硬件->键盘->切换软件键盘]

回答by Krishna Raj Salim

Try this:

尝试这个:

Goto:

去:

iOS Simulator -> Hardware -> Keyboard 

And Uncheck

并取消选中

'Connect Hardware Keyboard'

Or simply do: ? shift+ ? Command+ K

或者干脆做: ? shift+ ? Command+K

Keep Coding......... :)

继续编码......... :)

回答by MaryAnn Mierau

This can also happen with Xcode 6/iOS 8 because of simulator settings:

由于模拟器设置,这也可能发生在 Xcode 6/iOS 8 上:

Xcode 6: Keyboard does not show up in simulator

Xcode 6:键盘未显示在模拟器中

回答by Fred Hsiao

I've got the same problem but only on 5s simulator. And, I tried to go to simulator->reset content and settings. That actually solved the problem.

我有同样的问题,但只在 5s 模拟器上。而且,我尝试转到模拟器-> 重置内容和设置。这实际上解决了问题。

回答by Macrosoft-Dev

in this regard check two things

在这方面检查两件事

1-userInteractionEnabled=true

1-userInteractionEnabled=true

2- textFielfd.editable = YES;

2- textFielfd.editable = YES;

Hope this will solve your problem.

希望这能解决您的问题。

回答by washloops

check if at some point you're doing something like

检查是否在某个时候你正在做类似的事情

[self.view endEditing:YES];
[self.myTextField resignFirstResponder];

or maybe you're assigning the first responder to some other control.

或者您可能正在将第一响应者分配给其他控件。

Hope it helps

希望能帮助到你

回答by Joe

Also make sure you aren't messing with yourTextField.inputView

还要确保你没有搞砸 yourTextField.inputView

回答by rbs

Check if the outlet is mapped and the delegate set to the controller ? Also check if the controller has <UITextFieldDelegate>set. Send screen shot of the file inspector, perhaps?

检查插座是否已映射并将委托设置为控制器?还要检查控制器是否已<UITextFieldDelegate>设置。发送文件检查器的屏幕截图,也许?

回答by Rendel

I had the similar problem but on the actual device.
I talked to apple developer technical support (Apple DTS) and they told me that it's a swift compiler or Xcode bug.
I did a little workaround. Don't think that It's a best solution until apple solves this problem but it works without any problem now.

我有类似的问题,但在实际设备上。
我与苹果开发人员技术支持 (Apple DTS) 进行了交谈,他们告诉我这是一个 swift 编译器或 Xcode 错误。
我做了一些解决方法。不要认为这是一个最好的解决方案,直到苹果解决了这个问题,但现在它没有任何问题。

Just override the UITextField class:

只需覆盖 UITextField 类:

class PBTextField : UITextField {

var keyboardShowDate = NSDate()

required init?(coder aDecoder: NSCoder)
{
    super.init(coder: aDecoder)

    self.initialisation()
}

override init(frame: CGRect)
{
    super.init(frame: frame)

    self.initialisation()
}

func initialisation()
{
    self.addTarget(self, action: "editingDidBegin:", forControlEvents: UIControlEvents.EditingDidBegin)
    self.addTarget(self, action: "editingDidEnd:", forControlEvents: UIControlEvents.EditingDidEnd)
}

// MARK: Delegates

func editingDidBegin(sender: AnyObject)
{
    self.becomeFirstResponder()
    self.keyboardShowDate = NSDate()
}

func editingDidEnd(sender: AnyObject)
{
    if(fabs(self.keyboardShowDate.timeIntervalSinceNow) <= 0.5)
    {
        self.becomeFirstResponder()
        dispatch_after(0.1, block: { () -> Void in
            self.becomeFirstResponder()
        })
    }
}

}

dispatch methods:

派送方式:

typealias dispatch_cancelable_block_t = ((cancel: Bool) -> Void)

func dispatch_async(block: dispatch_block_t, background: Bool = true) -> dispatch_cancelable_block_t?
{
return dispatch_after(0, block: block, background: background)
}

func dispatch_after(delay: NSTimeInterval = 0, block: dispatch_block_t, background: Bool = false) -> dispatch_cancelable_block_t?
{
var cancelableBlock : dispatch_cancelable_block_t?

let delayBlock : dispatch_cancelable_block_t = { (cancel) -> Void in
    if(cancel == false)
    {
        if(background)
        {
            block()
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), block)
        }
    }

    cancelableBlock = nil
};

cancelableBlock = delayBlock

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * NSTimeInterval(NSEC_PER_SEC))), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
    if let cb = cancelableBlock
    {
        cb(cancel: false)
    }
})

return cancelableBlock
}

func cancel_block(block: dispatch_cancelable_block_t)
{
    block(cancel: true)
}

Hope this will help to someone.
If you got better solution, please let me know in comments.
Thanks
Giorgi

希望这会对某人有所帮助。
如果您有更好的解决方案,请在评论中告诉我。
谢谢你
的Giorgi

回答by Vineesh TP

Add [textField canBecomeFirstresponder];

添加 [textField canBecomeFirstresponder];