开发者

IOS Notification issue

I am working on Notification and my understanding on this is that IOS notificat开发者_StackOverflow中文版ions 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.


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.


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.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜