pickerview hidden when scrollview userInteraction Disabled - ios

My functionality is to open picker on click of textField. My textfield is inside scrollview is shown in below image.
I want to disable userinteraction of scrollview when picker opens. Following is my code.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.picker removeFromSuperview];
[self.toolBar removeFromSuperview];
textField.inputView = self.picker;
textField.inputAccessoryView = self.toolBar;
self.scrollview.userInterationEnabled = NO;
return YES;
}
When I comment the userInteractionEnabled code. Picker is opening perfectly. But when I uncomment code picker is not opened.
Also I gave some delay for this code. so after dalay my picker is hidden again.

The problem here is that userInteractionEnabled is inhereted from the scrollView to the textField. And as it is explained here
A UITextField will also refuse to become first responder if its userInteractionEnabled property is NO as I just discovered. I had to explicitly re-enable user interaction on the text field before it would accept first responder status.
And it can not show the inputView of the textField.
You shou ensure that your textField userInteracationEnables is true or to move the pickerView outside of the textField.inputView.

You can use this cool customizable control for having picker as an inputView on textfield.
Or this one if you want to disable the interaction to background view while picker is open.

Related

How to set keyboard as inputview in UItextfiled

I have one UItextfiled and in viewdidload i set his input view property as nil like this.
textField.inputView = nil
In in my view i have one button when i click on the button i have to set the textfield's inputview property as keyboard how can i do this.please help me.
I'm not exactly sure what you want to do, but probably you want your textField to became active, with a keyboard. That is done with
[textField becameFirstResponder];
and other way around is
[textField resignFirstResponder];

Tapping between UITextFields in iOS7

When a UITextField is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears.
If I tap another UITextField, the keyboard stays up, the first textfield is deselected, and nothing happens. Then I need to tap on the other UITextFIeld again for selection to happen and a keyboard to appear.
Is there a way to make a second UITextField immediately accessible when a first UITextField is selected?
If you reload the tableview in textFieldDidEndEditing, you'll break selection in this way. Don't do that.
try it, press another view should call below fn.
-(void)disappearKey{
[self.view endEditing:YES];
}
after keyboard disappear, Tap any textfield, will appear keyboard.
First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. It should be reported and Apple should fix it.
Using the textfield delegate methods and registering for keyboard notification it should be possible to manually keep track if the user tapped on another textfield and the keyboard did not close and reopen. At the very least you should be able to detect when this is happening and close the keyboard manually by [textField resignFirstResponder];
The keyboard notification are as follows:
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
I'm''pretty sure you know the UITextfield and textview delegate methods
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
I am not in an active project at the moment so I'm not sure if I just ignored the problem but I can't recall this happening to me.
you can use BSKeyboardControls. just see the demo and decide to
use or not.
or you can do you have to set tag in sequence to the each textfield
in uiview. then use the below code.
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}

iOS hide default keyboard and open custom keyboard

I have an UITextview, when user taps on UITextview i need to hide the default keyboard. For that i have done,
[myTextView setEditable: NO];
So the keyboard is not shown, here i have created an Custom View with UIButton, i need to show this UIView when the user taps on UITextView, for that i have done,
textViewDidBeginEditing{
//Here i have added UIView as subview
}
But this method is not working because of,
[myTextView setEditable: NO];
and i need to close the UIView when user clicks the close button inside the UIView
You should be using resignFirstResponder instead of setting the UITextView to not editable. This will hide the system keyboard.
[myTextView resignFirstResponder];
If you want to use a different view for the keyboard then the system provided one then set inputView on the UITextView to the custom view you want to be used in place of the system keyboard.
myTextView.inputView = myCustomView;
Perhaps using textFieldShouldBeginEditing instead of setEditable: NO works?
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Here i have added UIView as subview
return NO;
}

picker wheel that only appears when selected

I have a view controller that displays various UITextfields to edit information. For one UITextfield I need a picker wheel to select predefined statuses.
Problem is I don't have enough space to integrate a picker wheel, is there a possibility to make it appear only when the text box is selected?
You could set the UIPickerView as the UITextField's inputView.
This will ensure that the picker is shown automatically when the text field gets focus, and hides it when lost.
E.g.
myTextField.inputView = self.myPickerView;
See the documentation on this property.
Assuming your "picker wheel" is a UIView, just hook up your controller as the UITextField's delegate and implement the following:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.pickerWheel.hidden = NO;
}
You need to call your UIPicker in (BOOL)textFieldShouldBeginEditing:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textField==self.yourtextfield) {
//call your wheel in here
}
}
Look at
How to Show UIPickerView when selecting UITextField

Force keyboard to show up via button (iOS)

I have an UITextView and I don't want check editable option, how can call keyboard via a button?
This code doesn't work for me!
-(IBAction) yourButtonClick
{
[myTextView becomeFirstResponder];
[self.view addSubview:myTextView];
}
From the iPhone Application Programming Guide
However, you can programmatically
display the keyboard for an editable
text view by calling that view’s
becomeFirstResponder method. Calling
this method makes the target view the
first responder and begins the editing
process just as if the user had tapped
on the view.
So to show the keyboard programmatically,
[textView becomeFirstResponder];
However, the keyboard will never show if the textView is not editable.
The purpose of showing the keyboard is to allow editing. I assume you just don't want the keyboard to appear when the user taps the text view. In this case, you can enable editable programmatically when the button is tapped.
-(IBAction) yourButtonClick
{
myText.editable = YES;
[myText becomeFirstResponder];
}
Then in the UITextViewDelegate, disable editable when the user finishes editing.
- (void)textViewDidEndEditing:(UITextView *)textView {
textView.editable = NO;
}

Resources