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
Related
I have a textfield from which I show a popover for textfield value string.
When I edit the text field the clear button is visible, however, when I click the clear button,
textfield text doesn't disappear but the popover is dismissed.
How can I fix this please?
Below is code fragment
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
if(textField.tag == SERVER_TAG){
if ([[self getServerList] count]) {
[self createPopUp];
}
} else {
[serverNameTf resignFirstResponder];
}
}
- (BOOL)textFieldShouldClear:(UITextField *)textField {
return YES;
}
Its better if you paste your code that you tried.
But as i understood from your question, you may not set the TEXTFIELDs delegate,
so st the textfields delegate to self.
ie. textfield.delegate = self
and also make changes as >>
[textField setText:#""];
[popOverController dismissPopoverAnimated:YES];
Try this out.
if ([popOverController isPopoverVisible])
{
[textField setText:#""];
[popOverController dismissPopoverAnimated: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
I am designed one form with four UITextFields. First One for entering numbers, Second for entering name, third for choosing date and last one for choosing time. First textfield using Numberpad it will hide by using done button on the keyboard. If the user when enter into second (Name textfield) from first (number textfield) the first keyboard hide perfectly. If the user entering name and select date textfield am showing the datepicker in Actionsheet, when the user pick the date and hit done/cancel button i hide the actionsheet. But, the name textfield keyboard don't dismiss from the screen. I have tied below code, it is not working. Can anyone please suggest the idea for this clarification? Thanks in advance.
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == numberTextfield)
{
[textField setInputAccessoryView:keyboardToolbar];
}
else if(textField == nameTextfield)
{
}
else if(textField == dateTextField)
{
[self showdateActionSheet];
[nameTextfield resignFirstResponder];
[dateTextField resignFirstResponder];
}
else if(textField == timeTextField)
{
[timeTextField resignFirstResponder];
[nameTextfield resignFirstResponder];
}
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField // If the user select Return key it is dismissing fine
{
[nameTextfield resignFirstResponder];
return YES;
}
-(BOOL) textFieldShouldEndEditing:(UITextField *)textField
{
[nameTextfield resignFirstResponder];
return YES;
}
-(void) DateDone
{
[nameTextfield resignFirstResponder];
}
-(void) timeDone
{
[nameTextfield resignFirstResponder];
}
Gopinath. Please try my following code,
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField == dateTextField )
{
[nameTextfield resignFirstResponder];
[self showdateActionSheet];
[dateTextField resignFirstResponder];
}
else if( textField == timeTextField)
{
[nameTextfield resignFirstResponder];
[self ShowTime];
[timeTextField resignFirstResponder];
}
return YES;
}
I am sure i will help you.
Just do this:
self.view.editable = NO;
Link: How can I programmatically link an UIView or UIImageView with an event like “touch up inside”.
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