在添加子视图控制器时,我遇到了崩溃, 这里NavigationViewController是从UIViewController扩展而来的。
当我upgraded
到Xcode 9
,在早期版本的Xcode上成功运行时,会出现此错误。
我提到Link但没有得到任何满意的答案,请帮我解决这个问题,
提前完成。 :)
代码块是:
_mainSectionsController = [[[MainSectionsController alloc] initWithNibName:nil bundle:nil] autorelease];
[self addChildViewController:_mainSectionsController];
**Init method of _mainSectionsController** .
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
self.viewControllers = @
[
[[[NavigationViewController alloc] initWithNibName:nil bundle:nil]
autorelease]
];
return self;
}
**init method of NavigationViewController**
-(id)initWithNibName:(NSString*)nibNameOrNil bundle: (NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
_navController = [[[UINavigationController alloc] initWithNibName:nil bundle:nil] autorelease];
_navController.get().delegate = self;
_navController.get().navigationBarHidden = YES;
_navController.get().view.clipsToBounds = YES;
_navController.get().view.backgroundColor = [UIColor clearColor];
return self;
}
2018-05-22 10:46:23.112290 + 0530 [912:19925] - [NavigationViewController _viewControllerSubtreeDidGainViewController:]:无法识别的选择器发送到实例0x7f91ba83c000 2018-05-22 10:46:24.939903 + 0530 [912:19925] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [NavigationViewController _viewControllerSubtreeDidGainViewController:]:无法识别选择器发送到实例0x7f91ba83c000' * 首先抛出调用堆栈:
( 0 CoreFoundation 0x000000010f03f12b exceptionPreprocess + 171。 1 libobjc.A.dylib 0x000000010e640f41 objc_exception_throw + 48 2 CoreFoundation 0x000000010f0c0024 - [NSObject(NSObject)doesNotRecognizeSelector:] + 132 3 UIKit 0x000000010b2cdf51 - [UIResponder doesNotRecognizeSelector:] + 295 4 CoreFoundation 0x000000010efc1f78 ___ forwarding _ + 1432 5 CoreFoundation 0x000000010efc1958 _CF_forwarding_prep_0 + 120 6 UIKit 0x000000010b246c1d - [UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 696 7 UIKit 0x000000010b26930e - [UIViewController(UIContainerViewControllerProtectedMethods)addChildViewController:] + 83 8 0x00000001058eeac3 - [MainViewController initWithNibName:bundle:] + 5235 9 0x00000001059876ca - [AppDelegate loadMainViewController] + 122 10 0x0000000105984561 - [AppDelegate应用程序:didFinishLaunchingWithOptions:] + 1137 11 UIKit 0x000000010b091bca - [UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299 12 UIKit 0x000000010b093648 - [UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4113 13 UIKit 0x000000010b098aeb - [UIApplication _runWithMainScene:transitionContext:completion:] + 1720 14 UIKit 0x000000010b4626f8 111 - [__ UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] _ block_invoke + 924 15 UIKit 0x000000010b8384c8 + [_ UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153 16 UIKit 0x000000010b4622f1 - [__ UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249 17 UIKit 0x000000010b462b6b - [__ UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696 18 UIKit 0x000000010bde0a69 __82 - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] _ block_invoke + 262 19 UIKit 0x000000010bde0922 - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444 20 UIKit 0x000000010babd9c8 __125 - [_ UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] _ block_invoke + 221 21 UIKit 0x000000010bcbcb06 _performActionsWithDelayForTransitionContext + 100 22 UIKit 0x000000010babd88b - [_ UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231 23 UIKit 0x000000010b837b25 - [_ UICanvas场景:didUpdateWithDiff:transitionContext:完成:] + 392 24 UIKit 0x000000010b09736a - [UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523 25 UIKit 0x000000010b672605 - [UIApplicationSceneClientAgent场景:didInitializeWithEvent:完成:] + 369 26 FrontBoardServices 0x0000000116cb8cc0 - [FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338 27 FrontBoardServices 0x0000000116cc17b5 __56- [FBSWorkspace客户端:handleCreateScene:withCompletion:] _ block_invoke_2 + 235 28 libdispatch.dylib 0x000000010f87b33d _dispatch_client_callout + 8 29 libdispatch.dylib 0x000000010f8809f3 _dispatch_block_invoke_direct + 592 30 FrontBoardServices 0x0000000116ced498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24 31 FrontBoardServices 0x0000000116ced14e - [FBSSerialQueue _performNext] + 464 32 FrontBoardServices 0x0000000116ced6bd - [FBSSerialQueue _performNextFromRunLoopSource] + 45 33 CoreFoundation 0x000000010efe2101 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 34 CoreFoundation 0x000000010f081f71 __CFRunLoopDoSource0 + 81 35 CoreFoundation 0x000000010efc6a19 __CFRunLoopDoSources0 + 185 36 CoreFoundation 0x000000010efc5fff __CFRunLoopRun + 1279 37 CoreFoundation 0x000000010efc5889 CFRunLoopRunSpecific + 409 38 GraphicsServices 0x000000010fed99c6 GSEventRunModal + 62 39 UIKit 0x000000010b09a5d6 UIApplicationMain + 159 40 0x000000010590c331 main + 65 41 libdyld.dylib 0x000000010f8f7d81 start + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止
答案 0 :(得分:1)
由于您的pipe
代码中有autorelease
,我认为您不会在那里使用ARC。我强烈建议将MainSectionsController
和MainSectionsController
的代码升级到ARC。这可以防止可能导致此类问题的意外过度发布。
此外,我建议尽可能将NavigationViewController
分配从构造函数移至viewDidLoad。