UIViewController does not run. Methods not called

Greetings

This question seems to be an ongoing saga in the iphone SDK world ... so my contribution ...

There were two separate projects from the same template ... one is a semi-finished product, the other is not at all ... Please let me explain my steps ...

used this basic GL ES template //iphonedevelopment.blogspot.com/2008/12/opengl-project-template-for-xcode.html had to figure out some "Release" configuration, but in other situations there is everything I need to add orientation to the GL ES project.

One of my first projects, did my stuff, then added these methods ....

-(BOOL)shouldAutoRotateToInterfaceOrientation ..... -(void)willRotateToInterfaceOrientation .... -(void)didRotateFromInterfaceOrientation .... -(void)willAnimateRotationToInterfaceOrientation .... 

And to understand what they are doing (or trying to do in my case), (BOOL) follows ... is called once when creating the view controller and returns "YES". But after that, none of the other methods are called!

So, I started from scratch with an empty template (GL ES one on top) ... and added a minimum to support automatic rotation. But this time, none of the methods called!

So, I explored .... //developer.apple.com/iphone/library/qa/qa2010/qa1688.html as he said, I first added GLViewController.view and then added GLview as application delegate routines. Nothing!

Then it was found //www.iphonedevsdk.com/forum/iphone-sdk-development/44993-how-determine-ipad-launch-orientation.html which states that it allows receiving notifications of directions

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

and then disable them in the view controller ... it makes sense ... did it, nothing ...

I think that notifications can be enabled by default, although since I did not need to include them in the first project, but it still tries to check the orientation (i.e. (BOOL) shouldAutoRotate ...) ...

If anyone can help me, it will be very grateful, because this problem is driving me crazy. Thanks in advance.

The code can be found here ... http://rapidshare.com/files/392053688/autoRotation.zip

NB These projects avoid nib / xib resources, I would like to keep them that way, if possible.

IPad device iPad does not come out where I am, so I still can not test the device. It would be nice to work on a simulator.

+4
source share
2 answers

Well, that’s why, after the other pair leaned against the wall with the butt, she tried to do it manually ... hallelujah ...

so here is the result ... add these two lines so that they are called when creating the created controller ... ie in - (void) loadView or equivalent

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selectot(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

and set (void) should .... return YES

 -(void)shouldRotateToInterfaceOrienation { return YES; } 

delete everything..

 -(void)willRotateToInterfaceOrientation .... -(void)didRotateFromInterfaceOrientation .... -(void)willAnimateRotationToInterfaceOrientation .... 

they are not needed ...

and then add a method called didRotate

 -(void)didRotate:(NSNotification*)notification { UIDeviceOrientation oreo = [[UIDevice currentDevice] orientation]; // oreo is our new orientation! } 

basically the problem was that I made a half attempt to get it to work with the addition of beginGeneratingDeviceOrientationNotifications. I also needed to “capture” orientation events and process them myself ...

For purists who want to know why? I don’t know or understand why, sorry ... theoretically this should have worked, but in practice it is not.

+4
source

I had a lot of problems with didRoateToInterfaceOrienataion, which was not always called. shouldRotateToInterfaceOrientation was always called, but sometimes for some reason the status bar turned into landscape, but the view manager would not have been and didRotateTo ... was not called. I tried to override the NavigationController to support didRotateTo .. but I did not want all views in the NavigationController to support rotation.

In the end, I determined that the view BEFORE the one that supports rotation also had to support rotation. You might think that the problem will only be on this previous view, but for some reason the problem disappeared, and this was the only change.

Also this http://developer.apple.com/library/ios/#qa/qa1688/_index.html

0
source

Source: https://habr.com/ru/post/1311071/


All Articles