Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This one is kind of hard to explain, so ask any questions you need to clarify the question. I have an iPad app (XCode 4.2, iOS 6, ARC and Storyboards).

In this app, I have a UIPopover that contains a UIView with two (2) UITextFields in it and a UIDatePicker. (see image). When I go to that scene, I have unchecked userInteractionEnabled on both textFields to prevent the keyboard from responding, which works, but doesn't allow the other UITextField to be accessed after the first one. I tried [oFinishTime setInputView:oTimePicker]; but it takes the timepicker and moves it outside of the popover, which is unacceptable.

image showing 2 uiviews and a datepicker

I have touchUpInside events "wired" for each of the textFields, but neither one gets called when tapped due to UserInteractionEnabled being unchecked. I could remedy this whole thing if I could have it enabled and set a flag in the action event.

How can I enable both UITextFields yet prevent the keyboard from showing? I will be happy to post any relevant code you need to see.

share|improve this question
answer is already given, but a basicly question to your approach: why using Textfields instead of ´UITableView´ with 2 cells? in the ´didSelectRow:atIndexPath´ part show the picker and remember the cell that was tipped. maybe also a button for "set" or "set back" for the case user accidentally changed it ;) – geo May 19 at 0:06
Using textFields because that's the way I designed it. A UITableView would not accomplish what I need to do with the data. And the answer below is not complete because the taps are not being recognized. – spokane-dude May 19 at 0:16
I think you need to set the inputview of the textfield. – Muhammad Zeeshan May 19 at 8:22

2 Answers

up vote 1 down vote accepted

May be I did not understand your problem correctly , but it seems like you all you are trying to do is Open a picker on tap and display the value set in UIPicker. You are not really using any functionality of a UItextField. A label or a button might serve the same purpose and save you from doing the extra work of disabling the keyboard.

In any case if you want to use textfield and disable keyboard picker appearing as the input view and have your own input view to it, you could do

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    [textField resignFirstResponder];
}

You could take a look at this: Display datepicker on tapping on textfield

share|improve this answer
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.

assign delegate for each textfield and in the delegate method verify if its the one which should open picker instead of keyboard. If it is the one then return NO else YES

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
      if (textfield == startTimeTextField)
       { 
          [self openPicker];
          return NO;
        }
    return YES;
}
share|improve this answer
Taps are still not recognized on both textFields. If I can get the taps to be recognized, then I have this solved. User Interaction is enabled on both textfields. – spokane-dude May 19 at 0:00
I have updated the answer on how you can open the picker. And you may apply the breakpoint on this method just to verify if your delegate methods is being called or not. – yunas May 19 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.