iOS 9对UINavigationController实例的弱引用

时间:2016-04-28 01:24:31

标签: ios objective-c ios9 weak-references

我正在对应用进行维护。带有iOS 9.3的XCode 7.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];
}

我在哪里可以设置对实例的强引用?

1 个答案:

答案 0 :(得分:0)

在摆弄我的UINavigationController对象一段时间之后,我想出了这个解决方案:

- (void) setupNavigationControllerApp {

__strong UINavigationController *test = [self sideMenu].navigationController;

self.window.rootViewController = test;
[self.window makeKeyAndVisible];
}