Graphics Programs Reference
In-Depth Information
// Log the constant that represents the current orientation
NSLog(@"orientationChanged: %d", [[note object] orientation]);
}
Build and run the application. (This is best run on the device because the simulator won't
let you achieve some orientations. If you must use the simulator, you can change the ori-
entation by choosing
Rotate Left
or
Rotate Right
from the
Hardware
menu.)
Take another look at the
@selector
directive you used when you added an observer to
the notification center. This directive takes the name of a method and wraps it up in a
SEL
data type. Doing so allows method names to be passed as arguments to methods. But the
method name must be exact. Here, the name of the method is
orientationChanged:
including the colon. If you omit the colon from the
@selector
directive like this,
@selector(orientationChanged)
then the application will crash when the device rotates and for good reason: The notifica-
tion center will send the message
orientationChanged
to the
RotationAp-
pDelegate
.
RotationAppDelegate
does not implement to a method named
ori-
entationChanged
. It implements a method named
orientationChanged:
. The
colon is an essential part of the method name.
Many classes post notifications including
UIApplication
,
NSManagedOb-
jectContext
,
MPMoviePlayerController
,
NSFileHandle
,
UIWindow
,
UITextField
, and
UITextView
. See their class reference pages in the documentation
for details.