View Single Post
  #1 (permalink)  
Old February 28th, 2011, 01:25 PM
gNotapipe gNotapipe is offline
Authorized User
Points: 49, Level: 1
Points: 49, Level: 1 Points: 49, Level: 1 Points: 49, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2011
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Default Ch 6, Text re NSNotificationCenter question

In the text explaining the last Try It Out, "Shirfting Views" in Ch 6, Keyboard Inputs, there is something I find puzzling. (p176-178)
There are two methods messaging the NSNotificationCenter, viewWillAppear: and viewWillDisappear:.
The first reads:
Code:
//---before the View window appears---
-(void) viewWillAppear:(BOOL)animated {
	//---registers the notifications for keyboard---
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:self.view.window];
	
	[[NSNotificationCenter defaultCenter] 
	 addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
In the text, the author states:
"Finally, before the View window disappears, you remove the notifications that you set earlier:"
and then lists the 2nd method:
Code:
//---before the View window diappears---
-(void) viewWillDisappear:(BOOL)animated {
	//---remove the notifications for keyboard---
	[[NSNotificationCenter defaultCenter] 
	 removeObserver:self name:UIKeyboardWillShowNotification object:nil];
	
	[[NSNotificationCenter defaultCenter] 
	 removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
Note that the name values in the 2nd do not match those in the first. Given the explanatory statement, I would think that they should.
Is this, as I suspect, an errata, or is there something about NSNotificationCenter, or the code or the statement, I'm not understanding?
The code does work, so it certainly could be my newbness!
Reply With Quote