我正在执行一个应用程序的维护。XCode 7.3和iOS 9.3给了我一个我从未见过的错误:
“不能对类UINavigationController的实例(0x15243a00)形成弱引用。该对象可能被过度释放,或正在释放。”
我的AppDelegate中的违规代码如下:
#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];
}我可以在哪里设置对实例的强引用?
发布于 2016-04-28 01:58:52
在修改了UINavigationController对象一段时间之后,我想出了以下解决方案:
- (void) setupNavigationControllerApp {
__strong UINavigationController *test = [self sideMenu].navigationController;
self.window.rootViewController = test;
[self.window makeKeyAndVisible];
}https://stackoverflow.com/questions/36903640
复制相似问题