I want enter(Go.... etc) button on my iPad keypad. So that when I hit enter button on iPad keypad after entering username & password it should login & open next screen. I mean no need to press login button which I have design on my app. I have html pages in my application & I am able to hit Go,Search, refresh button by default. I want same Go button for iPad in Objective-C, Xcode framework. Only return button I can view by default on iPad, xcode framework . Can someone help me.....It can be easy one but I didnt found any code for the same.
It isn't hard at all.
Go into Interface Builder and open the current XIB you have placed the UITextField (I'm assuming).
What you want to do is, in the UITextField's property, is change the Return Key value to "Go" or whatever it is you want. I'm assuming you've already built the code for it to detect what UITextField is being edited and when the return key is tapped, what to do?
EDIT
Make sure that your UITextField's are delegated to the current ViewController. Then implement a delegate method. The following.
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == emailInput) {
[emailInput resignFirstResponder];
[passwordInput becomeFirstResponder];
} if (textField == passwordInput) {
[passwordInput resignFirstResponder];
[self performSelector:#selector(userLogin)];
}
return 0;
}
Therefore, when the emailInput's return key is hit, we jump to the passwordInput. When the passwordInput's return key is then hit, we perform a selector that issues the user login.
Related
I have two textfields (a username and a password) field and I remember that sometimes the keyboard has a little < or > to navigate through the textfields and I was wondering if there is an option or code that would allow me to do this natively in my app. Any tips or hints are appreciated. Thanks!
If you would like an acceptable solution that doesn't involve implementing a third party library, you can do it like the following:
Set the return button on the virtual keyboard to be a "Next" button for the username field, and a "Go" button for the password field, and make your view controller a UITextFieldDelegate. Set your view controller as the delegate for both text fields, then implement the textFieldShouldReturn: like the following:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.username) {
[self.password becomeFirstResponder];
}
else if (textField == self.password) {
[self.password resignFirstResponder];
[self signInPressed];
}
return YES;
}
This will make it so if you have the username field selected, the "Next" button on the keyboard will advance to the password field, and when the password field is selected, the "Go" button will call the signInPressed method, which you just change to whatever you have your sign in method named.
There's no builtin way to add these buttons.
Look into inputAccessoryView to understand how to extend the keyboard.
Editable textfield cells Tableview is causing problem on keyboard tab button everytime it is calling textfieldshouldbeginediting even if i am in first textfield it is not going to nextfield.
It is going to last textfield and if popover is availabe it will crash.How can i fix this so that if enter tab then it has to resign current responder in textfielddidendediting and it should not go to textfieldshouldbegin editing.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
PickerViewController *selectOperatorController;
NSLog(#"tag %d",textField.tag);
return NO;
}
I also declared textfield delegates like didendediting and shouldendediting
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
activeField = nil;
if (self.chooseOperatorController) {
[self.chooseOperatorController dismissPopoverAnimated:YES];
}
return YES;
}
This is not as issue in iOS 6.But it is in iOS 7.
textfieldshouldbegin editing will not allow desktop keyboard tab button input,it cannot judge to move between the textfields.If we add textfielddidbeginediting we can move the controls,eventhough we have two methods we can move by using keyboard tab.So textfielddidbeginediting is mandatory if we want to move bewtween available textfields.
There are many tabs in my screen,I want to give an alert box which says "Do you want to save the changes?" if user changes anything in the page, without clicking on the save button provided in the page,he is clicking on diff tab.
I'm able to get the alert view but the tab click moves the screen to the tab which was clicked. The screen should not change until the alert view is answered.
Can anyone let me know how to suppress the screen change until the alert view is answered ?
This doesn't directly answer your question, but: what you're trying to do sounds like bad UI design. (In general, if it feels like you are fighting against UIKit, you're probably doing it the wrong.)
In this case: if you really want to ensure that a user taps a Save button before moving to a different screen, you should present that screen in a modal view, so that it is impossible to navigate to any other part of the app.
In other words, if you want to prevent a user from navigating away from a screen, don't show them buttons or tabs that would allow them to navigate away. Otherwise, you're just making more work for yourself and frustrating a user.
Implement UITabBarControllerDelegate in your app delegate's applicationDidFinishLaunching
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
self.tabBarController.delegate = self;
[window addSubview:self.tabBarController.view];
}
Then use the below delegate method,
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
This method is called before the tab switch and you can return no here to disable that and show an alert message instead. Once the user has performed the save either he can press on tab again or you can programmatically switch to the new tab as,
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
Add this inside your delegate,
How about this for switching to the tab programmatically,
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if () {
//some code
} else {
//some other code
self.tabBarController.selectedViewController = viewController;
}
}
At the moment, I trigger a method on 'Did End On Exit' in my app (I'm aware that this may not be the greatest way of doing it but I'm very new to Objective C and Xcode for that matter and I'm simply doing what feels comfortable to me).
This method resigns the firstResponder from the current text field and applies it to a later text field.
The problem I'm facing is that the keyboard covers the next text field so that the use has no idea where the focus is and therefore what they are required to type.
How do I get it so that my keyboard shifts down and actually shows the text box that is currently active? Making something the firstResponder simply doesn't do what I want it to, unless there's part of the implementation I'm missing.
Here's my simple method:
- (IBAction)firstNameNext:(id)sender {
[firstNameTextField resignFirstResponder];
[surnameTextField becomeFirstResponder];
}
Any advice would be super.
Add UIScrollView in your main view then all contents as subview to UIScrollView
Now when specific UITextField needs to be able to visible in view use its delegate like this:
Note: add UITextFieldDelegate in .h file like this
#interface yourViewController : UIViewController<UITextFieldDelegate>
Also bind with File's Owner
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
{
if(textField == yourSpecficTextField) //one u want move upwards
{
yourScrollView.contentOffset = CGPointMake(0,200); //required offset
}
... //provide contentOffSet those who needed
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
yourScrollView.contentOffset = CGPointMake(0,0); //make UIScrollView as it was before
}
If you have keyboard input fields that will be covered by the virtual keyboard, then you need to move those fields out from under the virtual keyboard.
The normal way to do this is to have the controller's view be a scrollable view like UIScrollView. Moving Content That Is Located Under the Keyboard gives a very robust way of adjusting your scroll view and ensuring the required field shows.
I am making an app the iPhone. I have a text field the user can type into and it's working, but I want it so you can press a button and it saves the text so when you close and open the app again it is still there. I have the button ("Done!"), but I don't know how to program it.
Look into the NSUserDefaults class for easy ways to save simple data.
And to get the "done" button on the keyboard to respond, you need to implement the UITextFieldDelegate (or UITextViewDelegate) protocol and override the textFieldShouldReturn: method.
In that method write something like:
- (bool)textViewShouldReturn:(UITextView *)textView
{
[textField resignFirstResponder];
//code to save text to NSUserDefaults
return yes;
}