picker wheel that only appears when selected - ios

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

Related

UITextField animate input view frame animated

I am developing an application that displays a custom Keyboard (similar to Messenger's) (containing images).
I have been asked to add a button that changes the frame of the keyboard with an animation. But when i set the frame it does not change at all.
Is this possible to do ? Could this be done nicely or do i need some work around ?
You can use inputView Property Of TextField,
UITextField *textFieldWithCustomView;
UIView *customView;
[textFieldWithCustomView setInputView:customView];
and when you want to expand/Collapse use
- (void)toggleCustomView:(BOOL)expand
{
if (expand) {
[textFieldWithCustomView becomeFirstResponder];
}
else
{
[textFieldWithCustomView resignFirstResponder];
}
}
When you want to show key board use
[self toggleCustomView:YES];
Hope this helps.

if UITextField clicked

I am doing an application and I need to detect when a UITextField is clicked. I tried using touchesBegan but it doesn't react to textfield when clicked, only outside of it. I am only starting with Objective-C so if you give me advice, please let it be detailed. Thank you.
You can try the delegate method:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// Do something
}
As long as the text field has interaction enabled and is editable. However, a second tap will not be detected if the text field is already the first responder.
Set the textview's delegate property to an object that overloads the textViewShouldBeginEditing: function. You could also use the textFieldDidBeginEditing: function of the same delegate.

How to move to next screen on click of Read only text field iOS

I have a textfield that is readonly. I have another Search View Controller(VC) also. My aim is when the user clicks on readonly textfield it should open the searchVC. I tried attaching Push seque to SearchVC but it's not working. Tried same with a button and works seamlessly.
Pls suggest whats the approach for this.
You can use gesture to your textfield
or
You can use custom button above the textfield. You have to show/hide the button on textfield disabled/enabled
try this
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag==1)
{
//write alert view to check "click on this text filed alert is appearing"
return NO;
}
else if (textField.tag==2)
{
//it's behave normal uitextfiled
return YES;
}
}

How can I keep the select / select all / cut / copy / paste bar from appearing when I programmatically select text in UITextField

I've got a few instances of UITextField that I've added to some cells in a UITableView. I'm using the UITextField delegate to select all text in the textfield, like so:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[textField selectAll:self];
}
The problem I'm seeing is that I don't want the selection popup to appear the first time you touch the cell. I want to be able to edit the text, so I don't want to use becomeFirstResponder.
What you need is UIMenuController and you can hide it using - (void)setMenuVisible:(BOOL)menuVisible animated:(BOOL)animated so after your [textField selectAll:self]; call the above method to hide the menu.
EDIT
After a little search on google it seems that you will need to create a subclass of UITextField and override the - (BOOL)canPerformAction:(SEL)action withSender:(id)sender and return NO from this in order to hide the UIMenuController.
I can't test this right now since I'm not at my office but you should also try the following line [UIMenuController sharedMenuController].menuVisible = NO; before you start to implement a subclass of 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