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];
}
}