UITextView not becoming first responder in ios 7 - iphone

I am using the following control in a viewcontroller i want to show the keyboard when user opened the view so I tried to call this method from the viewcontroller
[self.inputToolbar.textView becomeFirstResponder];
But the keyboard does not show when opened the view. So i called the becomefirstresponder in the place where the textview is allocated you can see the allocation page here i called like this
[internalTextView becomeFirstResponder];
Now it works in iOS6 but in iOS7 it does not works

By using sample code
I write below code inUIInputToolbarViewController.m > loadView
[self.inputToolbar.textView.internalTextView becomeFirstResponder];
And it's working fine.
Code

Related

Showing keyboard at the right time iOS7

In iOS 6 I'm used to present keyboard in viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
[txtField becomeFirstResponder];
}
This way, when navigationController pushes the new viewController, keyboard is already there, animating smoothly from left to right and avoiding bottom-up animation.
In iOS 7 this behavior seems broken.
If I add [txtField becomeFirstResponder] in viewDidLoad, keyboard appears in the middle of pushing animation, already in its final position: an unpleasant effect!!
I've tried to move [txtField becomeFirstResponder] in viewWillAppear, but the final result is unchanged.
Do you know a way to get back iOS 6 behavior, pushing the new viewController and the keyboard all together?
EDIT: Using a timer doesn't work either... whatever time delay I set, the keyboard is shown only at the end of pushing animation.
So far, my best try it is to put [txtField becomeFirstResponder] in viewWillLayoutSubviews or viewDidLayoutSubviews. Unfortunately, doing so working when pushing viewController but not when popping back (the keyboard doesn't appear).
I've managed to extrapolate your workaround in viewWillLayoutSubviews to force it to work.
- (void)viewWillLayoutSubviews {
if (![self.textField1 isFirstResponder] && ![self.textField2 isFirstResponder] && ...) {
[self.textField1 becomeFirstResponder];
}
}
This is working for me for both pushing onto the stack, and after dismissing a modal view controller.

How can you program a UITextField's keyboard to open on viewDidLoad?

I want my UITextField's keyboard to stay open for the entire time I use this view controller. I don't want it to only open when my user touches the text field. In order to do this, I was hoping I would call the textFieldShouldBeginEditing method by doing this:
EDIT: thanks everyone, I just noticed I called my UITextField a UIImage field for some reason in the interface.
The textFieldShouldBeginEditing delegate method is not something that you call from your code. The OS calls the method when that particular event occurs, and you put code in there to run when the event is fired (similar to putting code in viewDidLoad for your view controller).
To show the keyboard whenever the view controller appears, simply call the UITextField's becomeFirstResponder method in the view controller's viewDidAppear method like this:
[self.myTextField becomeFirstResponder];
Don't forget to create an IBOutlet parameter for the UITextField, link it in Interface Builder, and replace self.myTextField above with the outlet that you created.
You should trigger your textview in viewDidAppear method:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.myTextField becomeFirstResponder];
}

Xcode search bar not running function

I am going crazy with this search bar in storyboards and have been trough loads of tutorials.
I have a search bar on my view and set it as an outlet
IBOutlet UISearchBar *searchBar;
how do I run code when the user clicks 'DONE' on the keyboard. I have tried this but nothing works
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
NSLog(#"Hello");
[searchBar resignFirstResponder];
}
I haven' used the storyboards for XCode, but have you made sure to set the viewController as the searchBar's delegate?
searchBarSearchButtonClicked should work, but have you tried searchBarResultsListButtonClicked and searchBarTextDidEndEditing. Btw, is this iphone or ipad? and check your delegate is set correctly.

iPhoneSDK: Weird bug after pushing a detailviewcontroller while the keyboard is still open

I have a very weird bug here, this is the scenario;
-I click on one of the textfields on my UITableView, uikeyboard appears,
-Then without pressing done, I click another textfield on screen(a disabled one),
-This disabled textfield pushes a detailview controller,
-I do my job on the detailview and return back,
-Surprize! the main UITableview is no more scrollable to bottom anymore! so I can not edit the bottom cells anymore!
This does not happen IF I press done after editing(so close the keyboard) and then click the detail view, now it works good.
I think it is something about resignfirstResponder is not called before I switch to another view, so I tried to send this msg to all the textfields in the tableview..but it got worse.
I tried also adding this line below just before I push the detailviewcontroller, but not worked, this is interssting cause this is what I call to resign the number pad normally, and it works when it is called from my custom "done" button to dismiss the nuber pad
[[self view] endEditing:YES];
And this is how I set the uikeyboards depend on the content in cellforRowAtIndex method
if(somelogic){
cell.textField.keyboardType=UIKeyboardTypeNumberPad;
[self resignFirstResponder];
[self becomeFirstResponder];
}
else{
cell.textField.keyboardType=UIKeyboardTypeDefault;
[self resignFirstResponder];
[self becomeFirstResponder];
}
Any Ideas?
Just call [currentTextField resignFirstResponder] before you push the detail view controller.
Set the currentTextField in the following method.
- (void)textFieldDidBeginEditing:(UITextField *)textField {
currentTextField = textField;
// Your code here
}
Occam's razor.
Don't let them not click the done button.
Put a transparent UIButton accross the entire screen. Show it when you call [textField becomeFirstResponder]. You can either prevent people from touching the screen and switching textFields, or call [textField resignFirstResponder] when it is tapped.

IPhone UITextField not showing edit caret or clearing placeholder text when tapped

I have a window within an iPhone application, which is displayed modally to allow the user to enter their settings for a web service upon 'first run'.
The text fields have helper text set, and when you tap them the keyboard shows and allows you to enter text.
Unfortunately the text fields do not clear the helper text, show the edit caret or show the text being entered (as in the screenshot below).
Any suggestions?
The window is being displayed with [self presentModalViewController:<controller_name> animated:YES];, which may or may not be the cause of this issue - when I run the UI via the Interface Builder 'test' application the text boxes respond like normal.
Clear when editing begins has been set for both fields.
Thanks in advance!
Edited: More information
After the info Bart Gottschalk provided I thought I should add some more information. First, the application is a Navigation Based Application.
Secondly, the test app Bart recommended worked fine, so that takes the modal window and the view out of the equation.
Third, I was presenting the modal view when the -(void)viewWillAppear... delegate method was being called - which may very well be the wrong place... however I'm not 100% sure if I should be presenting the modal view from within the didFinishLaunchingWithOptions of the App Delegate...
(this is happening on Simulator and iPhone 3.1.3)
In Interface Builder did you check the box for "Clear When Editing Begins"? With that checked the text field should clear any value once the use taps to edit which is the behavior I think you're looking for.
You can also set the same property programatically using clearsOnBeginEditing if that is convenient in your code.
My guess is that you've done this and it's not behaving as you expect. Just checking on this as a first step in helping you debug.
Also, does this happen in both the Simulator and on a testing device?
Bart
Edited Below...
This seems strange. Let's strip away everything but the basics of presenting a modal view when the application starts and see what happens.
I've recreated the most basic app (that I know of) to test presenting a modal view controller at launch and verify that field editing works fine. What happens for you when you do the same/similar in a new project?
Here is what I'm doing:
1) Create a new view-based app in Xcode called "ModalViewTest"
2) Create a new UIViewController with xib called ModalViewController
3) In ModalViewController.h add a method
-(IBAction)closeModalView;
4) In ModalViewController.m add the method implementation as
-(IBAction)closeModalView {
[self dismissModalViewControllerAnimated:YES];
}
5) In the ModalViewController.xib create two text fields and set the placeholder text for each to abcd1234 and confirm that "Clear When Editing Begins" is checked.
6) In the ModalViewController.xib add a button "Close" and set Touch Up Inside to fire "closeModalView"
7) In the application delegate (ModalViewTestAppDelegate) add the following import
#import "ModalViewController.h"
8) In the application delegate (ModalViewTestAppDelegate) applicationDidFinishLaunching add the following after the line containing [window makeKeyAndVisible];
ModalViewController *modalViewController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[viewController presentModalViewController:modalViewController animated:YES];
9) Save everything
10) Build and Run this new app
Does editing of the text fields work as expected? If yes, what is different about how you are building and presenting your modalView? If no, then we'll need to dig further to determine what is going on in your environment.
Second Edit Below...
When creating a navigation-based application I did the following to present the modal view at application start. Does this work for you in both your test app as well as your real app?
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
ModalViewController *modalViewController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[navigationController presentModalViewController:modalViewController animated:YES];
}
Well, I just figured it out, but honestly without the persistence and awesome help from Bart it would have taken much longer and been much more frustrating.
It turns out the problem was that I was using a Window instead of a View in the XIB file. This was why when showing the modal view within the Navigation controller it wouldn't display properly (i.e. only a white screen) and why the UITextField would not work properly when showing the view from the RootViewController.
So, to recap - modal views should have UIView, not UIWindow in the XIB/NIB File.
Thanks for your help Bart!
I have the same problem but in iOS7 only. I solved it by changing the tint color of textField to blue in the Storyboard