uipickerView is in the middle of view and change default inputview position - ipad

I have create an iPad application of data entry.
I use a Tableview for data entry end the cells is custom cell.
For the date I have created a textfield with a pickerview (UIDatePicker)
pickerView = [[UIDatePicker alloc] init];
[pickerView sizeToFit];
pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pickerView.datePickerMode = UIDatePickerModeDate;
self.dateField.inputView = pickerView;
The problem is that when I press on the textfield, it shows the pickerview in the middel of view and when I press the "Done" button to hide the pickerview the defaul position of the inputview (default keyboard) is not in the bottom of view but in the middle. If press again on the "Done" button of the picker view, the keyboard position increase its x value.
The problem is because when I show the pickerview, the keyboard is undocked (iOS5).
Is it possible to set the undocked - docked state of the keyboard in the code?
I have insert image of my problem:
Foto default keyboard
Foto Pickerview

Related

pickerview hidden when scrollview userInteraction Disabled

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.

How to hide the subView based on textfield value in iOS?

I am having four SubViews and two TextFields stateText and providertext.
If I click the stateText it shows a UIPickerView with two values. If I select the first value in the UIPickerView the view should not change and if I select the second value, this means that only third SubView has to change. In the same time, the selected picker value populates to TextFields.
If I select second value means the third SubView changes. But TextField values are not populated. Only this newSubView becomes active. Here is my Code:
PickerView Done Action
if([stateText.text isEqual:#"SecondValue"])
{
[self newSubView];
}
-(void)newSubView
{
UIView *loginView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+160, self.view.frame.size.width, 150)];
loginView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:loginView];
}

UIToolbar not responding in Custom UITableViewCell with UIPickerView

I've searched this for a while but can't find anything quite the same.
I have a UITableView, and when a certain row is selected, I insert another row below.
The inserted row is a custom tableviewcell which hold a UIPickerView.
The pickerview works fine, and when an item is selected it can trigger the notification, sending selected info back to the tableviewcontroller, and then remove the "pickerviewcell". All good there.
But this isn't ideal if the user wants to scroll back and forth on the uipickerview. So I've added a uitoolbar to the uipickerview with a Cancel & Done button.
But the Cancel and Done buttons never get fired.
From other items I have read, they talk about UIFirstResponder etc etc, but they are all related to making the uipickerview an inputaccessoryview for a uitextfield. But that is not what I am doing.
I've tried doing it all in code and via Storyboards, with the same results each time.
Some example below..
// (in my CustomTableViewCell's AwakeFromNib function)
let screenSize: CGRect = UIScreen.mainScreen().bounds
pickerView = UIPickerView(frame: CGRectMake(0,0, screenSize.width, 162))
pickerView.delegate = self
pickerView.dataSource = self
pickerToolbar.barStyle = UIBarStyle.Default
pickerToolbar.translucent = true
pickerToolbar.tintColor = UIColor.orangeColor()
pickerToolbar.sizeToFit()
pickerToolbar.userInteractionEnabled = true
pickerView.addSubview(pickerToolbar)
self.contentView.insertSubview(pickerView, atIndex: 3)
// both these logs show correct output
NSLog("picker subviews: %#", pickerView.subviews.description)
NSLog("toolbar subviews: %#", pickerToolbar.subviews.description)
Screenshot example:
By clicking on the "To" cell, the new cell is inserted which has the picker. The picker works fine by itself. But the Cancel button doesn't get triggered. It has an IBAction linked to it from Storyboard.
Clicking any cell also closes/removes the pickercell correctly.
I have made a picker within a UITextview and I using
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return NO;
and then dismissing the keyboard with
-(void)dismissKeyboard {
[_date resignFirstResponder];
}
where _date was my UITextfield property
Dismissing UIPickerView with Done button on UIToolBar
this is a really good post I found on this topic as well! I hope it helped.

How to disable keyboard when clicking a UITextField in iOS?

I am currently developing a prototype that I want to do user testing on desktop first before loading to iPad.
I am looking for solutions to disable the keyboard after clicking a textfield. That means after clicking a textfield, user is able to enter information from the macbook keyboard directly, and the virtual keyboard that automatically shows up in the simulator will not appear. I have been through a lot of tutorials but they are all dismissing the keyboard after user entry; that is not what I am looking for. How should I hide the keyboard?
Thanks so much!
Use this:
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
myTextField.inputView = dummyView; // Hide keyboard, but show blinking cursor
It works for UITextField and UITextView and they need to be set to editable.
What you did Here:
You created a dummy view of width=hight=0, & assigned it as the inputView of your textField.
How It works:
Instead of showing default, keyboard, now, the viewController is showing DummyView as inputView for your UITextField. As DummyView has Width=height=0, You will not see anything on the screen :)
Here is another answer which I found the same hack but with little additional supportive code snippet to hide the blinking cursor too.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO; // Hides both keyboard and blinking cursor.
}
I needed this to be done for a Quantity text field where I increase/decrease the quantity using a UIStepper view. So I needed the keyboard to be hidden always.
This will set the inputView of your textField to, basically, an empty UIView with no frame.
self.theTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];

how to disable uikeyboard of textview ,if the editing mode enabled

How to hide/disable keyboard ,if the textview editing is enabled.
I only want to that user can only be able to select the text and can't be allowed for entering text.
Because selected text will be converted in to image for move animation.
User will not be allowed for entering any text in textview so that's why keyboard should be hidden or disable ,he will be allowed only for text selection.
uitextview.editable = NO; or set checkmark in IB. It will allow to select text with options - Copy and Select All without keyboard appearing. Tap on the word and hold to select text.
ok just uncheck the behavior of you UItextview in .xib file.
Something to try it the 'editable' setting doesn't work out is to create a UIView that's hidden and out of the way somewhere and assign it as the inputView for the text view. If that property is non-nil, the view it contains will be shown instead of the keyboard.
Such as:
self.textView.inputView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)] autorelease];
try this
yourtextview.UserinterationEnable=No;
This will make the keyboard disappear:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
This what you want to do?

Resources