UIImagePickerController EXC_BAD_ACCESS Error

烂漫一生 提交于 2019-12-12 00:28:38

问题


I set up my app to run like this:

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:
                         [[UIScreen mainScreen] bounds]];

    UIImagePickerController* picker = [[UIImagePickerController alloc] init];

    self.viewController = picker;
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

After Image picker appears, I choose, for example, "Camera Roll". After that I press the back button (titled "Photos"). App crashes giving EXC_BAD_ACCESS error. When I enable zombie objects I receive "EXC_ARM_BREAKPOINT (subcode = 0xdefe)" error with following logs. Either:

[UIView willRemoveSubview:]: message sent to deallocated instance 0x2088ea20

or if I proceed with image selection:

-[PLImageScrollView willRemoveSubview:]: message sent to deallocated instance 0x1d82c910

On the other hand if I create a new project and put only stated code inside AppDelegate, code works as it should - no errors.

Now, I'm starting a new project and I will copy stuff from my previous project in order to find out what is the problem. If anyone has ideas why these errors occur, please share your thoughts.


回答1:


I found what was the problem. AppDelegate indirectly imported my own custom UIView category in which I (for unknown reasons) implemented dealloc method.

All views practically could not get deallocated properly. I deleted that dealloc method from that category and everything was allright.




回答2:


try declaring UIImagePickerController* picker in AppDelegate.h as class level variable. picker is getting deallocated after - (BOOL)application:(UIApplication *)application finishes.



来源:https://stackoverflow.com/questions/17365423/uiimagepickercontroller-exc-bad-access-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!