Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewController does not auto rotate

As the title says. My UIViewController will not rotate no matter what. When it loads shouldAutorotateToInterfaceOrientation is being called but after that it doesnt.

UPDATE 1:

It's a really really wierd problem. At least for me. And i ll try to explain everything.

It's a navigation based app. Every controller has

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES; 
}

Xcontroller is a child of Acontroller and it doesn't auto rotate. If Xcontroller become a child of Bcontroller then it will autorotate. So something is wrong with Acontroller. But Acontroller is identical (except its data) to Bcontroller.

Whats Wrong?

UPDATE 2:

I decided to recreate Acontroller. And it worked.I believe I was missing something stupid.

like image 910
looneygrc Avatar asked Mar 10 '10 11:03

looneygrc


2 Answers

I am not sure whether it's the same reason as your case. But I experienced the same thing. the shouldAutorotateToInterfaceOrientation was only called once in the beginning. After some serious debugging by taking code apart, I found that the reason is in my overridden init method. I had this before:

- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
    if (self) {     
        self.photoAlbum = theAlbum;     
    }
    return self;
}

And then I changed to this

- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
    if (self = [super init]) {      
        self.photoAlbum = theAlbum;     
    }
    return self;
}

Note: the only difference is I added [super init] to call the parent init. After this change, the rotation works well and the shouldAutorotateToInterfaceOrientation is being called everytime I rotate the screen. Hope this help.

like image 194
DaiLak Avatar answered Sep 23 '22 09:09

DaiLak


There can be several possible reasons your view controller does not rotate.

See Apple's official Q&A on this issue:

Why won't my UIViewController rotate with the device?

http://developer.apple.com/library/ios/#qa/qa2010/qa1688.html

like image 24
nybon Avatar answered Sep 23 '22 09:09

nybon