我正在对应用程序进行维护。 带有iOS 9.3的XCode 7.3给了我一个我以前从未见过的错误:
"无法形成对类 UINavigationController 的实例 (0x15243a00) 的弱引用。此对象可能被过度释放,或者正在解除分配的过程中。
我的应用程序委托中的错误代码如下:
#pragma mark - Setup Storyboard and Side Menu
- (UINavigationController *)navigationController {
UIStoryboard* sb = [[UIStoryboard alloc]init];
if (IS_IPAD) {
sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
}
else {
sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
}
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"principalView"];
return [[UINavigationController alloc] initWithRootViewController:vc];
}
- (MFSideMenu *)sideMenu {
SideMenuViewController *sideMenuController = [[SideMenuViewController alloc] init];
UINavigationController *navigationController = [self navigationController];
MFSideMenuOptions options = MFSideMenuOptionMenuButtonEnabled|MFSideMenuOptionBackButtonEnabled
|MFSideMenuOptionShadowEnabled;
//MFSideMenuOptions options = MFSideMenuOptionMenuButtonEnabled|MFSideMenuOptionShadowEnabled;
MFSideMenuPanMode panMode = MFSideMenuPanModeNavigationBar|MFSideMenuPanModeNavigationController;
MFSideMenu *sideMenu = [MFSideMenu menuWithNavigationController:navigationController
sideMenuController:sideMenuController
location:MFSideMenuLocationLeft
options:options
panMode:panMode];
sideMenuController.sideMenu = sideMenu;
return sideMenu;
}
- (void) setupNavigationControllerApp {
self.window.rootViewController = [self sideMenu].navigationController; //HERE IS WHERE I AM DETECTING THE APP CRASHING
[self.window makeKeyAndVisible];
}
在哪里可以设置对实例的强引用?
在摆弄了一段时间我的UINavigationController对象后,我想出了这个解决方案:
- (void) setupNavigationControllerApp {
__strong UINavigationController *test = [self sideMenu].navigationController;
self.window.rootViewController = test;
[self.window makeKeyAndVisible];
}