Custom textfield showing a pickerview - ios

I've created a custom subclass of UITextField which manages a custom datePicker.
I use this code :
self.flatDatePicker = [[FlatDatePicker alloc] initWithParentView:pickerContainer];
_flatDatePicker.datePickerMode = FlatDatePickerModeMonthAndYear;
[self.flatDatePicker show];
self.inputView = _flatDatePicker;
My problem
When I touch my custom text field, the picker pops but my ViewController is moved up. My question is how to remove this movement ? I don't know if it is the normal behaviour of this, but I would like a solution for that.

Related

Easiest way to set custom inputview to all textFields globally

I created a custom input view for the App I'm currently working on, I can assign this keyboard to a textField by doing:
textField.inputView = myCustomKeyboard as! UIView
Now I just want to switch out all inputViews with my custom inputView, is there a simpler way to do this without having to set the inputView on all the textFields separately in my app?
[[UITextField appearance] setInputView:customeView];
or swift:
UITextField.appearance().inputView = customeView
Please create custom view and add this line into app delegate did finish launching option

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];

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

How To Stop keyBoard Appearence at click event on UITextview?

In my IPad Application i am using TextView only for Text Displaying.As i need to display a Larger Text Thats Why i am using UITextview due to its Scrolling Property instead of using UILabel.
In my application i do not need to edit Text in UITextview ,but problem for me is that when i click on Textview for scrolling the keyboard appear its hide my textview so i want that my keyboard is never appear on click event.i make a search but not find any Suitable solution.Any help will be appriated.Thanx
NEW ANSWER (previous one was not working properly)
OK so since that is not working because it disables scrolling also, you should try to:
Implement UITextFieldDelegate protocol
In your view controller add the text
#interface YourViewController () <UITextViewDelegate>
In viewDidLoad set yourself as a delegate:
yourUITextView.delegate = self;
Implement the delegate method below:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}
When the textview is about to edit the text, this method will be called automatically. It returns no, so the editing won't start.
It is very important that you undo the changes from the previous answers: Do not set the editable field to NO
I tried it and it's working. Hope it helps!
OLD ANSWER
when you declare the variable, or in your viewdidload method, set the editable property to NO:
yourUITextView.editable = NO;
or
[yourUITextView setEditable:NO]
That should prevent the keyboard from appearing.
Go to .XIB file and you can uncheck behavior editable or programmatically
textView.editable = NO;

Resources