View Single Post
  #6 (permalink)  
Old March 2nd, 2011, 02:00 PM
thepianoguy thepianoguy is offline
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

The keyboard is not a treated as a view (as far as I can tell). I made a similar assumption that that was the view appearing and disappearing, and that the scrollView, being the delegate of the textView received messages as a result of this. In retrospect, not great reasoning on my part.(The method would probably had a signature like -keyboardViewDidShow if it was) It is the scrollView itself that receives these notifications and responds with the methods assigned to the particular notification when registering. The notifications are sent whether there are observers or not. Once registered an object will receive the notifications it is registered for until it removes itself as an observer. It is sort of like "If a tree falls in a forest…" You only hear it if you are set up to listen for it.

What is going on in the program is the following
-viewWillAppear is called and the scrollView is registered as an observer to the -UIKeyboardDidShow and -UIKeyboardDidHide notifications. -viewDidLoad is called after this. The keyboard shows and hides automatically as the textField becomes and relinquishes FirstResponder status. The scrollView receives the notifications from this and adjusts its view accordingly. The concept behind the program relinquishing observer status when the scrollView hides makes sense, since it will receive the notifications whether it is visible or not (showing and hiding the keyboard even though not visible). So offscreen - relinquish, return - reestablish.
-viewDidLoad is called only when the view is initialized, so the idea of using -viewWillAppear is that it is called each time the view returns. The issue arises - do
-viewWillAppear and -viewWillDisappear actually get called after the view is hidden? The answer is - it depends. If you add a secondViewController.view as a subView to the scrollView, it does not (There is a way to call it directly, but it is a one way street, try to call from the subView and design and encapsulation problems start to pop up and the idea of loose coupling goes out the window) Dismissing the subView and returning to the original view does not call -viewWillAppear even though the original view is no longer hidden.
I will be doing examples that makes use navigation and tabbar controllers to verify that things behave as expected when assigned to a main controller. (From some internet research, the calling of these delegate methods is tied into to an objects location on the stack)
More to come…
Bob
Reply With Quote
The Following User Says Thank You to thepianoguy For This Useful Post:
gNotapipe (March 4th, 2011)