UITextField as child of it's own inputAccessoryView - ios

I'm attempting to duplicate a UI similar to Messages. I have a UIToolbar pinned to the bottom of the view in a xib. On that toolbar is a UITextField. I've set the UITextField's input AccessoryView to be the UIToolbar. When I click on the UITextField, it snaps into position, but there's no keyboard underneath, just blank as if the keyboard was hidden. When I click on the UITextField a second time it animates with the keyboard. I've attempted to become it's delegate and all the other suggestions in other SO posts, but no luck.
#implementation ChatViewController {
IBOutlet UIToolbar *_keyboardAccessory;
IBOutlet UITextField *_textField;
}
- (void)viewDidLoad {
[super viewDidLoad];
[_textField setInputAccessoryView:_keyboardAccessory];
}

It will be simpler if you don't try to make the toolbar be the text field's inputAccessoryView. Just animate the toolbar up with the keyboard appears, and down when it disappears.
Everything you need to know to do this animation is documented in “Managing the Keyboard” in the Text, Web, and Editing Programming Guide for iOS. You can also find answers on stack overflow describing the process. here is an answer describing the process step-by-step with all the code.

Related

How to adjust Scrollview content size using autolayouts

Hi in my project i have added scrollview on viewcontroller and inside that scrollview i have added textfields and buttons
After that i have added auto-layouts for all fields as like below image there i have added bottom space container is "58"
but when i clicked on textfield i have changed scrollview content size like below and fine that's ok
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
[self.mainscrollview setContentSize:CGSizeMake(100, 700)];
}
here my main intention is when i clicked keyboard return button i want to set scroll view content size as like previous what i have applied
for this i have written some code but this showing exceptions please help me
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomSpaceContraint;
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.mainscrollview setContentSize:(100, bottomContraint.size.height)];
return YES;
}
Your question is not really clear, but if you want to adjust the scroll view based on the presence of the keyboard use the awesome framework TPKeyboardAvoiding. Also, you have tagged your question with swift, but the code you provided is objc. You might wanna change the tag.

Not properly add inputAccessoryView for UITextField

There is a requirement of inputAccessoryView is for the chat application.
When I add inputAccessoryView to UITextField on tap event of UIButton. That view is set as inputAccessoryView completely but text field is not becoming first responder.
(Note: Super view of textfield is viewText.)
- (IBAction)btnOpenTextField:(id)sender
{
UIView *accessoryView=[[UIView alloc]init];
accessoryView.frame=CGRectMake(0,0, _viewText.frame.size.width, _viewText.frame.size.height);
[accessoryView addSubview:_viewText];
_txtMessage.inputAccessoryView = accessoryView;
[_txtMessage becomeFirstResponder];
}
Thanks in Advance.
You can call [_textMessage reloadInputViews], replacing [_text becomeFirstResponder].
What you want to achieve is quite not possible, this will cause recursion, alternatively what you can do is put a textfield on bottom of the screen and when the textfield is selected you can animate it up with the flow of the keyboard. i think this is an appropriate solution if i got your question correctly.

UITableViewController scroll default behaviour

I'm using a UITableviewController with textField and text view in cells. By default when i click on a textfield the tableviewcontroller scroll the content up for let me se the content of the field. This default behaviour is very useful, but i've implemented a toolbar with a done button (inputAccessoryView) when i edit the textView. This is a problem when I switch from editing the textField to editing the textView, because the toolbar of the keyboard is just above the textView.
I've tryed a lot of solutions but nothing work for me. I've tryed something like this: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
but doesn't work for me because i suppose this behaviour is already implemented in UITableViewController.
PS: the UITableViewController was created with Interface Builder. I don't know if this information is useful.
If you set up your UITableViewController to implement the UITextViewDelegate protocol, then you can know when you begin editing the textView by implementing this method:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
//then you can scroll the tableview up so you can see the textView
[self.tableView setContentOffset:CGPointMake(0, /*height of your toolbar*/) animated:YES];
}

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