viewWillDisappear on page 233


What’s the point of the following statement in viewWillDisappear? By the time viewWillDisappear is called the view is about to be destroyed. Once the view is destroyed the keyboard is dismissed anyway.

In the XIB file we are making the file owner the delegate for each UITextField but UIDetailController doesn’t conform to UITextDelegate protocol. What gives?

[[self view] endEditing:YES];


Hi akshay,

I don’t think the view is actually destroyed when viewWillDisappear is called. I believe the system will only destroy a hidden view when faced with low memory pressure, i.e. viewDidUnload will be called. In any case, I think it’s good programming practice to get the view to relinquish the first responder status once it is not in view.

The setting of the delegate is not required (at least for this chapter). If you remove the delegate connections, everything should still work. Perhaps the author is teeing us up for the exercises in the next few chapters? I don’t think Obj-C will know (or care!) whether a delegate does conform to the delegate protocol during runtime. The only thing it can do is to check whether the delegate did actually implement any of the optional callback methods, before actually sending the messages to the delegate. Required methods however do not have the benefit of this check. Since the UITextDelegate protocol only defines optional methods and the delegate connections are materialized only at runtime, I think we are good. :slight_smile: If the setting of the delegate was done in code, and the protocol did actually declare required methods, then we should expect the compiler to generate warnings or errors about this. At least that’s my thinking anyway. :slight_smile: