Reputation: 3
While adding child viewcontroller, I am getting following crash, Here NavigationViewController is extended from UIViewController.
This error is coming when I upgraded
to Xcode 9
, working successfully on earlier versions of Xcode.
I referred the Link but not getting any satisfied answer, please help me out this,
Thanx in advance. :)
The block of code is:
_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:]: unrecognized selector sent to instance 0x7f91ba83c000 2018-05-22 10:46:24.939903+0530 [912:19925] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NavigationViewController _viewControllerSubtreeDidGainViewController:]: unrecognized selector sent to instance 0x7f91ba83c000' * First throw call stack:
( 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 application: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 scene:didUpdateWithDiff:transitionContext:completion:] + 392 24 UIKit 0x000000010b09736a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523 25 UIKit 0x000000010b672605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369 26 FrontBoardServices 0x0000000116cb8cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338 27 FrontBoardServices 0x0000000116cc17b5 __56-[FBSWorkspace client: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: terminating with uncaught exception of type NSException
Upvotes: 0
Views: 461
Reputation: 6290
Since you have autorelease
in your MainSectionsController
code I assume that you don't use ARC there. I highly recommend upgrading the code of MainSectionsController
and NavigationViewController
to ARC. This prevents accidental overreleases that might cause issues like this one.
In addition I'd recommend to move self.viewControllers
assignment from the constructor to viewDidLoad if possible.
Upvotes: 1