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.
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.
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
- (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;
}
Related
I am working on creating a custom keypad for my iPad app. I created this keypad as a custom inputView and then assigning it to the inputView attribute for each textfield. I built this keypad in storyboard, and when I place the cursor in any textfield, the delegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(#"how about here?");
return YES;
}
gets called, but the keypad for some weird reason breaks up and is spread all over the screen. I have no idea why this is happening.
Here is what the screen looks like when the app first loads:
and here is how the app looks after I place the cursor in a textfield which calls the above method:
Here is what my screen looks like when I turn Autolayout off:
I honestly have no idea why this is happening. What am I doing wrong?
Thanks in advance to all who reply.
I need a way to detect the case when user dismisses iOS keyboard manually, using "keyboard" button on keyboard. I tried to use UIKeyboardDidHideNotification, but quickly discovered that this event is also fired when user splits the keyboard, leaving it on screen.
Is there a way to know for sure that keyboard was really hidden?
To get solution I had to slightly modify my original implementation: I've replaced assigning nil to inputView member of my main view with creating and destroying custom invisible UIView<UIKeyInput> view to show and hide keyboard correspondingly. This allowed me to override this view's resignFirstResponder method which is always called on keyboard resigning - either in normal or in split state, when user dismisses keyboard using special button or when I remove it programmatically.
I believe that UIKeyboardDidHideNotification is only sent when the keyboard is truly gone. From the Apple docs:
Posted immediately after the dismissal of the keyboard.
However, you could also look to see if any of your inputs are currently the first responder:
BOOL keyboardUp = NO;
for (UIView *view in self.textInputs)
{
if (view.isFirstResponder)
{
keyboardUp = YES;
break;
}
}
I want to realize the function: when I click a button, a interface of keyboard will come out in a dependent interface. How can I do it? Just for iOS.
You need to add to your current view UITextField with frame = CGRectZero, create a reference to that textField in code and then on pressing button call becomeFirstResponder on textField.
You need to add an UITextField to your view and call then [myTextfield becomeFirstResponder]; Its possible to set the hidden attrribute from UITextField to YES - so the user will never see the textfield. After Keyboard input is finished you can remove the UITextField with removeFromSuperview.
Maybe a little bit dirty,but thats the solution I used often. I wonder if the SDK provide another possibility.
My app has two text fields in it's detail split. The first text field will permit the user to enter data by keyboard but the second by a picker presented inside a popover. Anyway, I want to let the keyboard (that will appear after editing the first text field) get dismissed when I press the text field that uses a popover. I used resignFirstResponder and the keyboard stays in place but it's disabled, like when I tap any keyboard key nothing happens (even the key to dismiss the keyboard doesn't work). So how can I hide the keyboard?
You should use
[textField resignFirstResponder];
not releaseFirstResponder (there is no such method)
As George said, you should call resignFirstResponder
But actually you might want to look at using the inputView property of the textField instead of using the pickerview in a popover.
You can say:
textfield.inputView = pickerview;
Why do you need the second UITextField? If you're not going to allow user input something with keyboard use UIButton (probably with custom design), show picker on press and update button's text on changes in picker
the most simplest thing to resign responders
[self.view endEditing:YES];
I have been looking for a similar questions but so far the answer doesn't fit my purposes. I have a UITableViewController inside A UINavigationController with custom UITableViewCells containing textfields inside. When I click on the textfields they become the firstResponders and when I click return they resign it. So far so good.
My problem is one of these cells is performs a Submit function. After this is done whenever I press the textfields the return button doesn't dismiss the keyboard anymore.
My question is, since I'm not releasing anything, why do these textfields stop listening to the resignfirstresponder message?
UPDATE: I finally got this working by setting an UITextfield ivar in the class, making it the first responder whenever the textfield begins editing in :
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField setTextColor:[UIColor blueColor]];
focusedTextField = textField;
}
And calling [focusedTextField endEditing:YES]; when i press the submit button. Just added this after seeing some answer in SO, but I can't remember the link, sorry.
Hope it helps.
If you have declared a method for return(let's say your textfiled is called textField) use this code in your method;
[textField setUserInteractionEnabled:NO];//but this may restric you if you need to use it again
But if you use standard return property of the keyboard it may be something related to Apple's restrictions