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
I suggest you put these in the init
and dealloc
methods, as the viewWillAppear
and viewWillDisappear
will be called every time the view appears or disappears, which is unnecessary for registering/deregistering notifications.
I'd nevertheless suggest you register as observer in viewWillAppear
and unregister in viewWillDisappear
since viewDidUnload
is called only when memory has to be freed, meaning viewDidLoad
get called much more often than viewDidUnload
and then you might have the problem of getting the same notification more than once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With