user3518271
user3518271

Reputation:

UIKeyboard not appearing when tapping on UITextField

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

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 UITextField white space is popping up, but the keyboard is not visible and I am not able to enter anything.

Upvotes: 56

Views: 46845

Answers (10)

Joe
Joe

Reputation: 3761

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

Upvotes: 4

Rendel
Rendel

Reputation: 1824

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.

Just override the UITextField class:

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

Upvotes: 1

Shekhu
Shekhu

Reputation: 2020

Following will fix the keyboard issue

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

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

Upvotes: 109

Krishna Raj Salim
Krishna Raj Salim

Reputation: 7390

Try this:

Goto:

iOS Simulator -> Hardware -> Keyboard 

And Uncheck

'Connect Hardware Keyboard'

Or simply do: ⇧ shift + ⌘ Command + K

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

Upvotes: 49

Fred Hsiao
Fred Hsiao

Reputation: 31

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.

Upvotes: 3

MaryAnn Mierau
MaryAnn Mierau

Reputation: 270

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

Xcode 6: Keyboard does not show up in simulator

Upvotes: 7

Vineesh TP
Vineesh TP

Reputation: 7973

Add [textField canBecomeFirstresponder];

Upvotes: 1

washloops
washloops

Reputation: 147

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

Upvotes: 2

rbs
rbs

Reputation: 112

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?

Upvotes: 1

Macrosoft-Dev
Macrosoft-Dev

Reputation: 2185

in this regard check two things

1-userInteractionEnabled=true

2- textFielfd.editable = YES;

Hope this will solve your problem.

Upvotes: 2

Related Questions