Declaring orientationChanged as an instance method?


#1

Hi everyone,

Just got the book a few weeks ago and I’m really enjoying working my way through it. Sorry if this is a stupid question, but here goes…

On page 161, we are asked to implement the method orientationChanged: in HeavyRotationAppDelegate.m. However, we do not define this method in HeavyRotationAppDelegate.h as an instance method. Why is this legal? My understanding (so far) was that we don’t have to declare instance methods in the header file for a class under two circumstances:

  1. If the method is already declared in the header file of the superclass and we want to override it, or
  2. If the method is declared in a protocol that the class conforms to.

I tried to find if orientationChanged: was declared anywhere in UIResponder or in UIApplicationDelegate, but I couldn’t find it. What am I missing?

Thanks!


#2

I seem to remember reading somewhere that you don’t have to declare methods in the .h file if you don’t want, it’s just good form and also allows XCode to autocomplete your code later.

I found this page on Stack Overflow that confirms it : stackoverflow.com/questions/1020 … -c-methods

But as for why the authors of the book don’t declare it in this example program I’m not sure. I would also like to know, as it’s got me curious. Please post if you find out

Thanks


#3

Hi, I’m writing this from Japan and wondered about same thing, It would be nice my pour English help you to understand.
In the method “-(BOOL) application:didFinishLaunchingWithOptions:launchOptions”(HeavyRotationAppDelegete.m),
you have coded “addObserver:selector:name:object” method.
this method registers AppDelegateObject as an observer,and tell NotificationCenter that this object requires "orientationChanged:"message when a notification occured.
You declared this in @selector compiler directive like “@selector(orientationChanged:)”.
If you change this string to something else like “orientationHasChanged”, you should change implementation to corresponding string.
thank you