I have a view that is initialized with – (id)initWithCoder:(NSCoder *)aDecoder
How do I initialize this view in a viewController?
I think I need the viewController if I want the view to autoRotate with the device. I am not sure, maybe I could accomplish the autoRotation without a viewController?
Adding a observer and shouldAutorotateToInterfaceOrientation: to the view did not autoRotate the view. But when I also add
-(void) orientationChanged:(NSNotification *) notification
{
NSLog(@"orientationChanged: %d", [[notification object] orientation]);
}
I get the orientation value in my console window.
Any help would be highly appreciated.
initWithCoder:is for managing serialized objects. You never call it directly. An object with aninitWithCoder:method should still have a regular designated initializer (for a view, it would beinitWithFrame:). Generally, however, I recommend using a nib file rather than trying to build this stuff by hand. It greatly simplifies things, and loading from a nib file will callinitWithCoder:.Managing autorotation with a view controller is much simpler. It’s not required, but it does do some of the work for you.