Question

I have two view controllers let's call them A and B

(1) in A I show a popOver containing a textField
(2) in B there is an UITextView used for simple text editing

I Have to manage the keyboard in A and in B to scroll the content hidden by the keyboard. I know how to reposition the content. What I need is a way to have different behavior on the same notifications types that in my are UIKeyboardWill(Show/Hide)Notification.
What I've done so far :
(1) I've added this code in each controller


    [[NSNotificationCenter defaultCenter] addObserver:self
                                  selector:@selector(keyboardDidAppear:)
                                      name:UIKeyboardWillShowNotification
                                    object:self.view.window
as I said I've added this code to A and B, but doesn't work as I expected. For instance When I click inside the textView two methods are triggered the keyboardDidAppear of A and the keyboardDidAppear of B, the same happens with the UIKeyboardWillHideNotification. I'm sure I'm doing something wrong, but honestly I can't figure it out.

Was it helpful?

Solution

I solved this problem changing the place in wich I register for the notification. To make sure that only the viewController visible is the controller that receive the notification I register for the notification in vieWillAppear and remove the notification in viewWillDisappear.

OTHER TIPS

Your syntax is a bit messed too, you need to add the word selector after the @ ...

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidAppear:)
                                                 name:UIKeyboardWillShowNotification
                                               object:self.view.window];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top