Unable to resign keyboard when using PopOver - iphone

In my iPad app there are 3 textboxes where i am using popoverview controller on second text box.
here their are 2 cases
In First Case:
As i finish editing the first textbox and click the next button on keyboard that time the keyboard is resigning perfectly and the popoverview controller is opened on second text box.Here i had written the code when the next button of the first textbox click at that time the second textbox should became FirstResponder.
In Second Case:
Here the actual problem,
When i finish editing the first textbox and directly touches the second textbox without clicking the next button on keyboard, that time popoverview controller menu is opened on second textbox and the keyboard is unable to resign , the keyboard is strucking over their my code for resigning the keyboard is not working.

Write your code which you used on NEXT button event of Keyboard in this bellow method...
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
if (textField == yourFirstTextBox) {
// write your code here
}
return YES;
}

-(void)textFieldDidBeginEditing:(UITextField *)textfield
{
if ([textfield tag]==yourtextfieldtag)//set tag for your textfield
{
[yourfirsttextfield resignFirstResponder];
[yoursecondtextfield resignFirstResponder];
.
.
.
//Write all textField with resignFirstResponder
}
}

Here is the way you can handle your SoftKeypad
Handling Soft Keypad in iPhone Tutorial
There are three simple ways to handle keypad here
Keypad go back when Button clicked.
Keypad go back when user click on Return or Done button on keypad.
Keypad go back when user Touch on Background screen/view.
Just follow 3rd way in you case.
What you need to do is just crate a method in which call
method for the desired text field.
and Updated Related UIView class to UIControl in Interface Builder.
as I have written all the information step by step to make it more easy and clear.
Here is the responsible code snip
- (IBAction)keypadGoBack:(id)sender {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
Hope this will help you.

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField==yourTextField)
{
[self.view endEditing:YES];
// Write Your Popoverview Code / Extra Code
return NO;
}
return YES;
}
Here this method will get called when you will hit textfield.
And check the textfield with yourtextFieldName if its match..it will resign all keyboard.if there is more than one also..with the help of.
[self.view endEditing:YES];
And you can do Extra Code also For popoverview and return no means It will not give keyboard to that perticuler textField.
Thanks.

Related

how to hide keyboard on ipad while pressing arrowkey

In iPad we have
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textFieldOne resignFirstResponder];
[textFieldTwo resignFirstResponder];
return YES;
}
but also we can close keyboard on arrow key so whcich that method of arrow key on which we can show something
here is the screenshot
There isn't any function which gets called when "Hide Keyboard" button is clicked on iPad. If you want to perform any action when keyboard goes down. You can either use following function :
- (void)textFieldDidEndEditing:(UITextField *)textField
Or, you can use keyboard notifications i.e. UIKeyboardWillHideNotification.

Hide IOS keyboard with multiple textFields

I have 2 textFields side by side, countryCodeTextField and cellphoneTextField
On countryCodeTextField. I have an action selectCountry that happens on Edit Did Begin on the countryCodeTextField
- (IBAction)selectCountry:(id)sender {
countryCodeTextField.delegate = self;
[countryCodeTextField resignFirstResponder];
Note that self implements the <UITextFieldDelegate>.
Problem is when user click's cellphone the keyboard is displayed if he clicks on countryCodeTextField the keyboard is never dismissed.
If the person clicks the countryCode first then the keyboard never appears(which is what I want).
Why isn't the keyboard hidden when the user clicks cellphoneTextField first and then countryCodeTextField?
If you don't want the user to be able to edit a particular UITextField, set it to not be enabled.
UITextField *textField = ... // Allocated somehow
textfield.enabled = NO
Or just check the enabled checkbox in Interface Builder. Then the textfield will still be there and you'll be able to update it by configuring the text. But as sort of mentioned in comments, users expect UITextFields to be editable.
Also, why are you setting the delegate in the IBAction callback? I would think you'd be better off doing this in Interface Builder or when you create the UITextField in code.
EDIT:
Ok - so you want users to be able to select the box, but then bring up a custom subview(s) from which they select something which will fill the box.
So set the UITextField delegate when you create it (as mentioned above) and implement the following from the UITextFieldDelegate protocol:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
to return NO. Note that if you are using the same delegate for both of your UITextFields, you will need to make this method return YES for the other field. For example, something like:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField == countryTextField)
return NO;
return YES;
}
Hopefully this should stop the keyboard being displayed - and now you have to work out how to fire your own subviews, which I'd suggest doing via an IBAction (touch up or something perhaps). You'll have to test various things out here, but remember you're kinda corrupting the point of UITextField and maybe it'll work and maybe it won't, and maybe it'll break in the next iOS upgrade.
Okay, so first, I think you shouldn't be using a UITextField. I think you should be using a UIButton and have the current value showing as the button's title. However, if you have your heart set on it, I would use our good friend inputView, a property on UITextField, and set that to your custom input view (which I assume is a UIPickerView or similar.)
This has the added bonus of not breaking your app horribly for blind and visually impaired users, something you should probably be aware of before you go messing about with standard behaviour.
In your method :
- (IBAction)textFieldDidBeginEditing: (UITextField *)textField
call this :
[textField becomeFirstResponder];
and apply checks for the two fields i.e., when textField is the countryCodeTextField write :
[textField resignFirstResponder];
and call your method :
[self selectCountry];
In this method display the list of country codes.
So Your code will be :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
- (IBAction)textFieldDidBeginEditing: (UITextField *)textField{
[textField becomeFirstResponder];
if (textField == countryCodeTextField){
[textField resignFirstResponder];
[self selectCountry];
}
}
-(IBAction)selectCountry{
//display the list no need to do anything with the textfield.Only set text of TextField as the selected countrycode.
}

sign in view controller , iphone

I have 2 text fields, one is for usrname and the other one is for password.
Question : after entering a username and hit next from the keyboard, how can I jump to the password field for typing a password..
Any comments are welcomed here.
Check this question. It pretty much clarifies on how to implement what Juan said. How to navigate through textfields (Next / Done Buttons)
You need to implement the UITextFieldDelegate protocol and use the becomeFirstResponder method to change the focus to the next textField.
The method you need to implement on the delegate is textFieldShouldReturn:.
This is a sample implementation I have:
-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
[passwordField becomeFirstResponder];
if (self.passwordField == textField) {
[self loginAction:textField];
}
return YES;
}
You can set the implementing class delegate for both of your text fields.
Hope it helps!
What would you like to have to signify that someone has finished typing? Whatever that condition is, just use the
[myTextField becomeFirstResponder];
method to make the next text field be in control of the keyboard. Effectively this will create the "jump".
Furthermore, you can do this to hook up the next button to be the trigger for the jump.
//amount received animations
[myTextField setDelegate:self];
[myTextField setReturnKeyType:UIReturnKeyDone];
[myTextField addTarget:self
action:#selector(methodThatJumps:)
forControlEvents:UIControlEventEditingDidEndOnExit];
and in the method that jumps, simply use the above line. Let me know if you'd like me to explain it better.

How Can I Hide The Keyboard iPhone App

How can I hide the keyboard after the user presses 'Done', or taps the UITextField?
I have put this code in the AppDelegate:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
And I have linked the UITextField delegate in IB to the File's Owner..
What am I doing wrong?
EDIT: Changin return NO -> return YES does nothing. I have IB open and clicking on file's owner -> connections tab, there are multiple referencing outlets all pointing to the UITextfields. It still isn;t working..
UPDATE:
I added this to my function:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
int i = 5;
NSLog(#"%d", i);
return YES;
}
Nothing is getting printed to the console when I press return after setting focus to the textfield...So it's not calling the function. Have I connected something up incorrectly? I have the return key acting as 'Done'too, not sure if that makes a difference?
UPDATE:
I had my testfieldShouldReturn function in my AppDelegate instead of my viewcontroller. My mistake....Thanks for your help guys
Your code looks good. Can you make sure that you do have the delegate connection set up correctly? Try adding an NSLog to the delegate method to see if it is even being called.
...
Your question update points to this definitely being a connection issue. Try what Vince suggests and set the delegate explicitly in code. You'll probably want to do this in the viewDidLoad method of your view controller to ensure that the textField has actually been loaded before you set its delegate. Post back about whether that works.
Just set your app delegate as the delegate of your UITextField.
[textField setDelegate:self];
Set it in the -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; method of your app delegate.
Since you want the textfield to return. You should return YES; instead of NO.
In your .h
-(IBAction)hideKeyboard:(id)sender;
In your .m or .mm
-(IBAction)hideKeyboard:(id)sender {
[(UITextField*)sender resignFirstResponder];
}
Then just link them in Interface builder to your text field's "Did End On Exit" event.
Replace return NO; with return YES;.
This works in my code.
EDIT: I was wrong. The return value is not the problem here. The keyboard should hide when you call resignFirstResponder.
Hope this video tutorial will help you..
http://www.thenewboston.com/?p=1368&pOpen=tutorial
Call that textFieldShouldReturn function on return key Press to do this:
1) right click text field from where the key board pops up.
2) Select first option "Did end on exit".
3) Drag blue line to files owner and you will have an option to select "hideKeyboard" function option
And you are done.

Simulate Tab Key Press in iOS SDK

When a hardware keyboard is used with iOS, pressing tab or shift-tab automatically navigates to the next or previous logical responder, respectively. Is there a way to do the same programmatically (i.e. simulating the tab key rather than keeping track of the logical order manually)?
As William Niu is right but you can also use this code explained below.
I have used this and got success.Now consider the example of UITextField...
You can use UITextView's delegate method -(BOOL)textFieldShouldReturn:(UITextField*)textField as explained below.
But before doing this you should have to give tag to each UITextField in an Increment order...(Increment order is not required necessary ,but as for my code it is required, you can also use decrement order but some code changes for doing this)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [self.view viewWithTag:nextTag];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return YES;
}
Hope this will work for you...
Happy coding....
You may define the "tab-order" using the tag property. The following post describes how to find the next tag index to go to for UITextFields,
How to navigate through textfields (Next / Done Buttons).
Here is a modified version of the code from that post. Instead of removing keyboard at the last tag index, this following code would try to loop back to the first tag index.
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
return NO;
}
// Try to find the first responder instead...
// Assuming the first tag index is 1
UIResponder* firstResponder = [textField.superview viewWithTag:1];
if (firstResponder) {
// loop back to the first responder
[firstResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
If you want an UI element other than UITextField, you should still be able to use the same logic, with a few more checks.
Not sure if this helps, but in the context of a UITextFields, if you implement UITextFieldDelegate, - (BOOL)textFieldShouldReturn:(UITextField *)textField will get called when the return key of the soft keyboard is pressed.
I've tried to hit directly on my laptop keyboard and it seemed to jump between all the textfields in the order in which you've added them to the view, but didn't go to any other types of fields (Buttons etc.).
key on the keyboard is simulating the key on the soft keyboard of the simulator, which works as expected.