I'm using an open source messaging UI library for an app that I'm building. When users start a new conversation I want the "chat view" to appear with the keyboard already up and the cursor on the textfield (similar to most existing chat applications). Is there a way to force the JSQMessagesViewController to appear with the keyboard already up?
I tried implementing this using:
self.keyboardController.textView.becomeFirstResponder()
However, this caused the keyboard to pop up immediately when the view was presented... yet the toolbar would lag behind by about a second (not too much, but painfully noticeable). In addition, this solution seems to disable the keyboard from being dismissed using a downward gesture as it normally does.
Is there something I'm missing that solves this out of box? Or will I have to modify the library to get this bit of functionality... and if so, where do I begin doing that?
try to do like this
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[myTextField becomeFirstResponder];
}
--> It will make focus on myTextField and open the keyboard automatically. Hope it may help you.
This worked for me. It's in swift, but should be easy to translate.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(false)
self.inputToolbar!.contentView!.textView!.becomeFirstResponder()
}
I wanted this with a button click so I added:
[self.inputToolbar.contentView.textView becomeFirstResponder];
If you want yours when it loads add:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.inputToolbar.contentView.textView becomeFirstResponder];
}
This maybe too late, but in my case I forgot to call super.viewDidAppear(animated) which caused text view to lag behind keyboard. Once I added that call, problem went away.
Related
does anyone knows how to disable the swipe forward and backward feature in ios.
I am using angularjs and stuck in a problem where user can swipe back and forward this disturbs my functionality of the app. any lead would be appreciated.
I don't think you can accomplish exactly what you are trying to do. I have run into this issue as well - where I need to save some piece of data before the user goes back to a previous view controller. Reacting to a button tap is easy with an IBOutlet and some simple logic. But when the user has the ability to swipe to go back with functionality built into UINavigationControllers, it's not so cut and dry now.
Instead of trying to swim against the current, why not use this new ability?
Using viewWillDisappear, check if the current view controller is no longer in self.navigationController's stack. If it isn't than we are Oscar Mike to a different view controller and you should save your data.
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
[self saveImportantData];
}
[super viewWillDisappear:animated];
}
While I'm sure this isn't what you asked for, maybe it is a workaround that will help you.
if u have the access to viewcontroller file,then u can use the above code to disable the screen panning
- (void)viewDidLoad {
[super viewDidLoad];
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
I am new to stackoverflow and iOS app development using Swift. When I want to dismiss the keyboard in my apps I connect the uitextfield in viewcontroller.swift and create an action with the event DidEndOnExit. Then in that method I call the self.resignFirstResponder() method. This is what everybody says I should do. Here is my code in viewcontroller
#IBAction func dismissKeyboard(sender: AnyObject) {
self.resignFirstResponder()
}
Now when I was searching to find out what this method does I found that when I choose the textfield then the keyboard appears and that textfield becomes the first responder and by calling this method it resigns the first responder and the keyboard disappears. The thing is that if I don't use this method the keyboard still disappears. All I need to do is to create the action with the DidEndOnExit event. Am I missing something here? Here is the code without the method;
#IBAction func dismissKeyboard(sender: AnyObject) {
//self.resignFirstResponder()
}
If someone can enlighten me that would be great! :)
Thanks in advance!
maybe you enabled "Auto-enable Return Key" in the Interface builder?
The only thing that could come to mind is that you have an auto enabled return key. You also said it wasn't enabled, so maybe it has something to do with the rest of your code in the ViewController. Also, check any properties that you could have been playing with to get it to work, like you said you are new to swift so you we probably playing around with getting the keyboard to dismiss.
Sometimes Xcode can be a little buggy, if you can't solve the problem or get the right answer my advice is make a new project and add just the keyboard dismissing code in.
I hope this helps you out a little not seeing the rest of the code, screen shots and etc. make it so I can only give my thoughts or past experiences!
Good luck! Have fun programming in swift.
I need a way to detect the case when user dismisses iOS keyboard manually, using "keyboard" button on keyboard. I tried to use UIKeyboardDidHideNotification, but quickly discovered that this event is also fired when user splits the keyboard, leaving it on screen.
Is there a way to know for sure that keyboard was really hidden?
To get solution I had to slightly modify my original implementation: I've replaced assigning nil to inputView member of my main view with creating and destroying custom invisible UIView<UIKeyInput> view to show and hide keyboard correspondingly. This allowed me to override this view's resignFirstResponder method which is always called on keyboard resigning - either in normal or in split state, when user dismisses keyboard using special button or when I remove it programmatically.
I believe that UIKeyboardDidHideNotification is only sent when the keyboard is truly gone. From the Apple docs:
Posted immediately after the dismissal of the keyboard.
However, you could also look to see if any of your inputs are currently the first responder:
BOOL keyboardUp = NO;
for (UIView *view in self.textInputs)
{
if (view.isFirstResponder)
{
keyboardUp = YES;
break;
}
}
I have been looking for a similar questions but so far the answer doesn't fit my purposes. I have a UITableViewController inside A UINavigationController with custom UITableViewCells containing textfields inside. When I click on the textfields they become the firstResponders and when I click return they resign it. So far so good.
My problem is one of these cells is performs a Submit function. After this is done whenever I press the textfields the return button doesn't dismiss the keyboard anymore.
My question is, since I'm not releasing anything, why do these textfields stop listening to the resignfirstresponder message?
UPDATE: I finally got this working by setting an UITextfield ivar in the class, making it the first responder whenever the textfield begins editing in :
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField setTextColor:[UIColor blueColor]];
focusedTextField = textField;
}
And calling [focusedTextField endEditing:YES]; when i press the submit button. Just added this after seeing some answer in SO, but I can't remember the link, sorry.
Hope it helps.
If you have declared a method for return(let's say your textfiled is called textField) use this code in your method;
[textField setUserInteractionEnabled:NO];//but this may restric you if you need to use it again
But if you use standard return property of the keyboard it may be something related to Apple's restrictions
I am making a Login Screen for my ViewBased Application.I am having a problem, when i click on the UITextField the onscreen screen pops up as it should. But when i am done with typing the Onscreen Keyboard is not removing from the screen.
Can any one suggest me how can i solve this issue?
Thanks in advance
set the delegate of the UITextField to ViewController class. Override textfieldShouldReturn and call resignFirstResponder...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
EDIT:
After seeing the comment It seems you are a beginner...This blog post tells about UITextField and delegates..Also when you have time, please read this post too (to learn about protocols and delegates..)