By clicking on the back button, I save the information from the UITextFields
of the UIView
. When the information in a UITextField
is not correct and I click on the back button, I want to open the keyboard, but my view dissapears. How to stop the UIView from dissapearing and open my keyboard instead.
I think I should put my code in a viewShouldDissapear, but there is no such method.
This is my code:
- (void) viewWillDisappear:(BOOL)animated
{
if ([textField1 length] < 3 || [textField1 length] > 17) {
tableView.contentInset = UIEdgeInsetsMake(65, 0, 10, 0);
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:7 inSection:indexPath.section]
atScrollPosition:UITableViewScrollPositionTop animated:NO];
[txtSerieSasiu becomeFirstResponder];
return;
}
if (shouldSave)
[self save];
}
I'm assuming that you have back button on navigation controller.
Then add a custom button there and if everything is correct then dismiss it other wise show keyboard
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"goback.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(popVC:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}
- (void)popVC:(id)sender
{
if (isValueCorrect) {
[self.navigationController popViewControllerAnimated:YES];
}
else{
[textView becomeFirstResponder];
}
}