2

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.

geo
  • 1,781
  • 1
  • 18
  • 30
SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • 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 '13 at 00: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. – SpokaneDude May 19 '13 at 00:16
  • 1
    I think you need to set the inputview of the textfield. – Muhammad Zeeshan May 19 '13 at 08:22

2 Answers2

5
- (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;
}
yunas
  • 4,143
  • 1
  • 32
  • 38
  • 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. – SpokaneDude May 19 '13 at 00: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 '13 at 08:44
5

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

Community
  • 1
  • 1
ila
  • 920
  • 12
  • 35