6

I am testing out a simple application on Xcode 5.0.2. Using storyboard, I've dragged two view controllers that are connected by segues. On first view controller there is a button, after pressing that button next controller shows up which has two textfields. When I tap the textfield, the keyboard is not showing up and the text cursor is missing.

textFieldViewController.h file

@property (weak, nonatomic) IBOutlet UITextField *nameField;

@property (weak, nonatomic) IBOutlet UITextField *numberField;

- (IBAction)textFieldDoneEditing:(id)sender;


- (IBAction)backgroundTap:(id)sender;

textFieldViewController.m file

 - (IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
}

- (IBAction)backgroundTap:(id)sender {
    [self.nameField resignFirstResponder];
    [self.numberField resignFirstResponder];
}

screenshot enter image description here

bneely
  • 9,083
  • 4
  • 38
  • 46
hellosheikh
  • 2,929
  • 8
  • 49
  • 115

4 Answers4

12

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

Xcode 6: Keyboard does not show up in simulator

Community
  • 1
  • 1
MaryAnn Mierau
  • 270
  • 4
  • 8
2

Make sure that your UserInteraction of UITextfield is Enabled and you didnot have any view on your Textfield.

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
jayraj m.g.
  • 625
  • 5
  • 18
  • the userinteraction is enabled and there is no view – hellosheikh Feb 17 '14 at 11:57
  • is Particular UITextField is Enabled from your storyboard? or you can set it programmatically like following: UITextField *txtfld=[[UITextField alloc]init]; txtfld.userInteractionEnabled=YES; txtfld.enabled=YES; – jayraj m.g. Feb 17 '14 at 12:01
  • can you drag and drop uitextfield directly to that view without any code and connectivity and check what is going on? – jayraj m.g. Feb 17 '14 at 12:22
  • yeah i tried but this new text box also not showing keyboard which has not code yet – hellosheikh Feb 17 '14 at 12:28
  • is that same things runs on your mainview controller or first screen? – jayraj m.g. Feb 17 '14 at 12:32
  • yeah sorry i figure out the problem the user interaction was disabled on the view controller but was enabled on the textfield .. thankyou for all of you for helping me – hellosheikh Feb 17 '14 at 12:34
0
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{//Text Field Delegate

     [textField resignFirstResponder];

    return TRUE;
}

can u try this and set the textFields delegate using storyboard

or use

- (void)viewDidLoad
{
  nameField.delegate = self;
  numberField.delegate = self;
}

an in textFieldViewController.h file

change to @interface textFieldViewController : UIViewController <UITextFieldDelegate>

LML
  • 1,659
  • 12
  • 29
  • thank you for your answer but it still didnt work. i keep tapping the textfield but nothing happens – hellosheikh Feb 17 '14 at 11:46
  • did you noticed my edit? and do you correctly implemented the IBOutlet connection with the storyboard – LML Feb 17 '14 at 11:48
  • yeah i noticed and i think i correctly implemented it .. let me show you the screen shot – hellosheikh Feb 17 '14 at 11:52
  • i have updated my question ..take a look on the image i attached – hellosheikh Feb 17 '14 at 11:54
  • Can u please add a connection from the delegate in the right to the textField in the left – LML Feb 17 '14 at 11:58
  • yeah sorry i forgot. but still no luck – hellosheikh Feb 17 '14 at 12:00
  • One more try remove the Did End On Exit Event connection – LML Feb 17 '14 at 12:02
  • okk.sorry i have to ask something {textFieldShouldReturn} this method is connected to any thing .. is this method is called autometically ? – hellosheikh Feb 17 '14 at 12:04
  • its a delegate method when you connect the delegate with textfield it should called automatically – LML Feb 17 '14 at 12:05
  • i think somethings wrong . when i add a connection from the delegate to the right of the textfield it connects but the name appears in front of the delegate on right side is "Control" not the method name .. i think it has to show the method name right? – hellosheikh Feb 17 '14 at 12:11
  • thankyou for your help.i figure out the problem. thanks really appreciate your help – hellosheikh Feb 17 '14 at 12:35
0

I have had this issue and in my case, I have a custom view that displays various subviews on demand. Everything was fine, until the release of iOS 7.1.

So I was creating an UITextField when (1st case) my view was about to be added as subview and when (2nd case) the view was initialized (initWithFrame: method). I have seen so many solutions where the responder chain was modified or the tint color changed. But in my case, I got my stuff behaving normally only with that one thing:

I placed the initialization code for the UITextField into a lazy-getter and scheduled a delayed call of this method.

-(UITextField*)textField {
    if (!_tf) {
        _tf = [[UITextField alloc] initWithFrame:self.bounds]
        // (... more code to set up the text field ...)
        [self addSubview:_tf];
    }
    return _tf;
}

And then, (I had already overridden this method, so I deceided to call this here):

-(void)didMoveToSuperview {
    [super didMoveToSuperview];
    if (self.superview) {
        // (... other code ...)
        [self performSelector:@selector(textField) withObject:nil afterDelay:0.04];
    }
}

And it works for me.

Anticro
  • 685
  • 4
  • 12