问题
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