I have a view with 2 text fields for the user inputs.But when clicking on those text fields,keyboard is not showing.I have connected the delegate and implemented the following method.username and password are my text fields.
- (BOOL)textFieldShouldReturn:(UITextField*)txts{
[username resignFirstResponder];
[password resignFirstResponder];
return YES;
}
Are they over released? Are they nil? Try assigning them to the first responder.
[textField becomeFirstResponder];
then implement BOOL method
-(BOOL)canBecomeFirstResponder {
return YES;
}
Are you sure you have set the delegate?
[textField setDelegate:self];
Did you connect them properly if you used them in XIB?
Related
I have two textfields which are of type UITextField.
I have two buttons click and cancel.
The idea is to enter two numbers and it will navigate to next view. This View should display those two numbers.
The problem is if I click on the textfield one then the keypad is responding; when I click return it does not jump to the next field.
-(BOOL)textFieldShouldReturn:(UITextField *)textField{[textField resignFirstResponder];return YES;}
You need to connect UITextFiled Delegate from nib or programeticuly like this image:
or
other way is programmatic like in your viewDidLoad method or viewWillAppear method:
Yourtxtfild.delegate = self;
EDIT
for jumping AnotherView Use this textfiled delegate method:-
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
//you can set your textfiled string in to globle Variable and use it in another viewController
YourViewCntroller *objViewController = [[YourViewCntroller alloc] initWithNibName:#"YourViewCntrollernib" bundle:nil];
[self.navigationController pushViewController:objViewController animated:YES];
}
You have to set the delegate of the textfield as the object of the class where you have written the textFieldShouldReturn: method.
#Ragavan : You are just resigning the first textfield, but you are not making the other textfield to respond. So, use the code below as reference to make it work.
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField1 resignFirstResponder];
[textField2 becomeFirstResponder];
return YES;
}
In my iPad app I have two textfields. One displays the normal, default textfield and the other should display a picker as its input view.
Problem is, once I use the txt1 which displays default keyboard and then when I touch the 2nd textField the txt1 keyboard is staying visible.
I have also written [txt1 resignFirstResponder]; [txt2 resignFirstResponder]; while displaying the picker.
I have checked the txt1 IBOutlet connection and the delegate assignment, those seem to be correct.
What am I missing?
Write the following code :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
return YES;
}
else
{
return NO; // Write the code for displaying UIPickerView instead of the Keyboard.
}
}
Hope this might solve your issue......
txt2.userInteractionEnabled = NO;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txt1)
{
[txt2 resignFirstResponder];
// code for Hide Picker
return YES;
}
else {
// [txt2 resignFirstResponder];
[txt1 resignFirstResponder];
// code for go in picker
return YES;
}
}
for more information
You have to implement below method to resign Keyboard......
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Have u implemented this method ??
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
In your viewDidLoad method write this,
txt2.inputView = pickerView;
and other resignFirstResponder codes should be placed correctly , by this on Tapping txt2, you will directly get pickerview instead of Keyboard.
did you implement the delegates property of UITextFieldDelegates to in the header file, if not do that and check
Already the second day and cannot figure out the problem,
I've UITabelView with Custom UICellViews, each custom UICellView consists of UILabel and UITextField.
Custom UICellView object allocs UITextField and UILabel in its init method and are released in dealloc.
The number of custom UICellViews in UITableView is 6.
The user scenario is following
When user clicks from from 1 to 5 UITextFields virtual keyboard opens and user types some text
When user clicks on the 6th UITextField if virtual keyboard is active, it should be hidden, and if it is hidden it shall not be displayed.
As implement UITextFieldDelegate protocol in my UIViewController class and set the delegate of each UITextField to self.
My delegate methods are following
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag != 6) {
return YES;
} else {
[textField resignFirstResponder];
return NO;
}
}
-(BOOL) textFieldShouldEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(void) textFieldDidBeginEditing:(UITextField *)textField {
/* Some code */
}
-(void) textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
All the functions are properly !
So now, the virtual keyboard is never get hidden, why this happens ?
PS. Similar code has worked on iPhone but this issue exists on iPad.
You need to know which textfield was last used! so you can do [lastUsedTextField resignFirstResponder]
There is a dirty, but working trick.. you can make your textfield the new active UITextField and call resignFirstResponder in the next cycle immediately:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag != 6) {
return YES;
} else {
// this will schedule keyboard dismissal for the current text field
dispatch_async(dispatch_get_main_queue(), ^{
[textField resignFirstResponder];
});
return YES; // -> make this one active
}
}
did you seted action for textField?
[YourTextField addTarget:self action:#selector(textFieldDoneEditing:) forControlEvents:UIControlEventEditingDidEndOnExit];
PS set any selector for any ControlEvent
I have a view with two UITextField, one for username, one for password.
I added functionality so the usernameTF return button jumps to the passwordTF. I also made the return button on the passwordTF "Go" which I want to connect to a IBAction I have which will contain the actual login logic.
I tried hooking up the IBAction to the passwordTF's Did End On Exit method but that just seemed to be getting called when the usernameTF was making the passwordTF the first responder.
I'm using this code to jump from usernameTF to passwordTF:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.usernameTextField) {
[self.passwordTextField becomeFirstResponder];
}
[textField resignFirstResponder];
return YES;
}
I tried this but it does't call the method when I press Go/Return:
[self.passwordTextField addTarget:self
action:#selector(loginButtonPressed:)
forControlEvents:UIControlEventEditingDidEndOnExit];
I also tried connecting the IBAction to the UITextField's Editing Did End method which calls the method fine when I press the return button, but it also calls the method when I click any UITextField other than the one I have connected with that method. Any fix?
You can try using this
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
if (textField == txtfEmail)
[txtfPassword becomeFirstResponder];
else {
[self login];
}
return YES;
}
Where [self login] is actually the login method being called. Validating login credential from Server or from Database. txtfEmail is Login Name and txtfPassword being the password field. Hope it helps
#RahulSharma is almost there, but not quite.
It has 2 issues addressed by the following approach:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
// [textField resignFirstResponder];
if (textField == txtfEmail) {
[txtfPassword becomeFirstResponder];
return NO; // Otherwise the "Return" char is posted onto next view
} else {
[self login];
}
return YES;
}
invoking resignFirstResponder is not necessary
returning NO will ensure that the CR will not be sent to the next control
can anybody help me in such situation:
I have SigninController class with two textFields (as Outlets) txtLogin and txtPassword:
when I filled txtLogin, I call [txtPassword becomeFirstResponder] to pass input focus to next field (return button works fine in txtLogin), but Return button doesn't work in txtPassword and I can't dismiss keyboard in this case. What did I write wrong ?
Example code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == txtLogin) {
[txtLogin resignFirstResponder]; //Works as I think
[txtPassword becomeFirstResponder]; // txtPassword gets focus
} else {
[self signinClick]; //Never enter here
}
return YES;
}
- (IBAction)signinClick
{
NSLog(#"Signin Clicked");
[activityIndicator startAnimating];
[txtPassword resignFirstResponder];
..........
}
It seems you have forgot to set the delegate of txtPassword correctly.
specify
urtextfieldobject.delegate=self;
then urViewcontroller.h
#interface urViewcontroller
make sure both of them