简体   繁体   中英

iOS Rotating Phone crashes

I support portrait only ATM, I get these error when rotating the device:

[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890'

This is in iOS5.1. Initially I just left the default portrait clause in, but changed it to:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) { // Or whatever orientation it will be presented in.
        return YES;
    }
    return NO;
}

I am using ARC btw.

Hoping that would help stop the crashing. My info.plist has portrait and portrait upside down. There is nothing else I have done thats stock practice except my main view has multiple ViewControllers and its set to:

self.wantsFullScreenLayout=YES;

Any ideas peoples? Thanks in advance.

My project adds the main view from the appdelegate as such:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
mainViewController=[[MainViewController alloc] init];

[self.window addSubview:mainViewController.view];

And I have 2 ViewControllers on that mainViewController and I use a Navigation controller to push several ViewControllers as such:

- (void) loadActionsView {


NSArray* views = [self.navigationController viewControllers];

if ([views containsObject: actionsPanelViewController])
{
    [self.navigationController popToViewController:actionsPanelViewController animated:YES];
} else {

    [self.navigationController pushViewController:actionsPanelViewController animated:YES];
}

[[StateModel stateModel] setCurrentScreenIndex:0];

}

This is the first view that is called btw.

Update 2 with Solution/problem found:

I was using part of SHK the SHKActivityIndicator, that had a notification that was capturing the screen rotation and its selectors where causing the issue:

[[NSNotificationCenter defaultCenter] addObserver:currentIndicator selector:@selector(setProperRotation) name:UIDeviceOrientationDidChangeNotification object:nil];

It sounds like your ViewController is released and another Object receives setProperRotation message. Check if your ViewController is alive.

mainViewController=[[MainViewController alloc] init];
[self.window addSubview:mainViewController.view];

here is the problem. You adding only the view. ARC thinks that you dont need your MainViewController anymore.

  • Make MainViewController as a Class variable or
  • set window.rootViewController

     self.window.rootViewController = mainViewController; 

The exception shows that you are likely over-releasing an object which is supposed to responds to -setProperRotation . Look for that object and try to understand where you forgot to retain it (for example, track its retains and releases with Object allocation instrument)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM