When the text field is empty and user tapped on the back button which action method will it call? My requirement is when the user tapped on the back button and text field is empty cursor will be on the previous text field.
Asked
Active
Viewed 180 times
-3
-
can you show some code what you had try out – Bhupat Bheda Apr 24 '17 at 12:14
-
you need to track field previous textfield and call [previoustextfield becomeFirstResponse] in click of back button. – KKRocks Apr 24 '17 at 12:16
-
I am not getting any action methods which will call when text field is empty when text field have some text "shouldChangeCharactersInRange" called. – Vikash Dummy Apr 24 '17 at 12:16
-
show some screen shot – Anbu.Karthik Apr 24 '17 at 12:17
-
@kkRocks but when text field is empty I am not getting any action methods – Vikash Dummy Apr 24 '17 at 12:18
-
exactly what you want to do ? – KKRocks Apr 24 '17 at 12:19
-
is it navigation back button ? – KKRocks Apr 24 '17 at 12:25
-
I have 4 text fields. by default, keypad cursor is on the first text field. when the user enters any key, entered text will show on first field and cursor will go on the second screen. Now the user is taping on keypad back button. now cursor will be on the first field but any delegate methods are not calling when the user tapped on keypad back button. – Vikash Dummy Apr 24 '17 at 12:27
-
check this : http://stackoverflow.com/a/12874641/3901620 – KKRocks Apr 24 '17 at 13:05
1 Answers
-1
I think you need to add a custom back button and define its action.
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setFrame:CGRectMake(0,0,30,30)];
backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[backButton addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barBackButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
navitem.hidesBackButton = YES;
navitem.leftBarButtonItems = @[barBackButtonItem];

Shivam Gupta
- 9
- 2