Question

I am working on Notification and my understanding on this is that IOS notifications like "textFieldShouldBeginEditing:(UITextField *)iTextField" gets posted only when you tap on a text field.

To my strange notice, my code is receiving this notification when I am tapping on "Back" button to go back to my previous view.

What are the possible chances of me getting this notification again. I believe we need not to register for such notifications. I have registered only for keyboard hide/show notifications.

Please suggest.

Was it helpful?

Solution

I found the issue. The issue was I was adding my textfield as first responder before server call and then was only removing it when you hit the return button or hit any other text field. That's why it was not getting resigned when back button was pressed. Now I have resigned it soon after server call.

OTHER TIPS

Edit: I misunderstood the question. See the OP's answer.

Well, the keyboard will disappear upon navigation. It makes sense that the notification is posted in this case. One way to ignore notifications generated in response to view transitions is to keep track of your view controller's state.

- (void)viewWillDisappear:(BOOL)animated {
    _transitioningView = YES;
}

- (void)viewDidDisappear:(BOOL)animated {
    _transitioningView = NO;
}

- (void)viewWillAppear:(BOOL)animated {
    _transitioningView = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    _transitioningView = NO;
}

Now, in the selector called by your keyboard notification, you can just return if the view is transitioning.

- (void)keyboardWillHide:(NSNotification*)notif {
    if (_transitioningView)
        return;
    // Handle keyboard dismissal.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top