views:

86

answers:

1

Hi all,

I have a drill down navigation app with three levels of UIViewControllers. In each view controller, I have a UITextField where I am trying to subclass the UIKeyboard for each. My question is where to "set" notifications and "unset" them.

I have the notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

so it it best to set them in the viewDidLoad event? Or the viewWillAppear event?

And likewise for [[NSNotificationCenter defaultCenter] removeObserver:self];

I don't want to have multiple keyboardWillShow: events to be called as I drill down.

Many thanks, Brett

+1  A: 

I suggest you put these in the viewDidLoad and viewDidUnload methods, as the viewWillAppear and viewWillDisappear will be called every time the view appears or disappears, which is unnecessary for registering/deregistering notifications.

Jacob Relkin