Application Crash on ios11 & Xcode 9: while adding [self addChildViewController:] - objective-c

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

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.

Related

issue with UISplitViewController in iOS 8.1: [UISplitViewController navigationBar]: unrecognized selector sent to instance

Im trying to create a New UISPlitViewController and display it instead of current ViewController, but for some reason it's not working, it says:
-[UISplitViewController navigationBar]: unrecognized selector sent to instance
this is the code
- (IBAction)openDocuments:(id)sender {
UINavigationController *leftNavController;
UINavigationController *rightNavController;
MenuDocumentsVC *masterVC = [self.storyboard instantiateViewControllerWithIdentifier:#"MenuDocumentsVC"];
masterVC.title = #" ";
ContentDocumentsVC *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ContentDocumentsVC"];
detailVC.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
masterVC.delegate = detailVC;
leftNavController = [[UINavigationController alloc] initWithRootViewController:masterVC];
rightNavController = [[UINavigationController alloc] initWithRootViewController:detailVC];
leftNavController.toolbarHidden = FALSE;
rightNavController.toolbarHidden = FALSE;
leftNavController.navigationBar.translucent = FALSE;
rightNavController.navigationBar.translucent = FALSE;
leftNavController.toolbar.translucent = FALSE;
rightNavController.toolbar.translucent = FALSE;
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
splitViewController.delegate = (id)detailVC;
if ([splitViewController respondsToSelector:#selector(setPresentsWithGesture:)]) {
[splitViewController setPresentsWithGesture:NO];
}
splitViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[UIView transitionWithView:self.view.window
duration:0.5
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.view.window.rootViewController = splitViewController;
} completion:^(BOOL finished) {
}];
}
how to make it work properly??
Exception
2015-01-05 11:01:47.402 myapp[3454:607] -[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00
2015-01-05 11:01:47.406 myapp[3454:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00'
*** First throw call stack:
(
0 CoreFoundation 0x010a21e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00a718e5 objc_exception_throw + 44
2 CoreFoundation 0x0113f243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0109250b ___forwarding___ + 1019
4 CoreFoundation 0x010920ee _CF_forwarding_prep_0 + 14
5 eOpenRoad 0x00056d7d +[Functions setNavigationBarControllerToHexColor:] + 333
6 eOpenRoad 0x0004fa15 -[ContentDocumentsVC viewWillAppear:] + 69
7 UIKit 0x0163e04b -[UIViewController _setViewAppearState:isAnimating:] + 448
8 UIKit 0x0163e548 -[UIViewController __viewWillAppear:] + 114
9 UIKit 0x01660c25 -[UINavigationController _startTransition:fromViewController:toViewController:] + 800
10 UIKit 0x016618cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x016624e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x017a30d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0158a964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x00a8382b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x001ea45a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x001de244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x001ea3a5 -[CALayer layoutIfNeeded] + 160
18 UIKit 0x0164cae3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
19 UIKit 0x01562aa7 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
20 UIKit 0x01561646 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
21 UIKit 0x01561518 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
22 UIKit 0x015615a0 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
23 UIKit 0x0156063a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
24 UIKit 0x0156059c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
25 UIKit 0x015612f3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
26 UIKit 0x015648e6 -[UIWindow setDelegate:] + 449
27 UIKit 0x0163eb77 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
28 UIKit 0x0155a474 -[UIWindow addRootViewControllerViewIfPossible] + 591
29 UIKit 0x0155ac84 -[UIWindow setRootViewController:] + 960
30 eOpenRoad 0x0005c5ec +[Functions openContentInWindowWithParameters:insideOfNavigationController:] + 7804
31 eOpenRoad 0x0001f42b -[ViewController openDocuments:] + 555
32 libobjc.A.dylib 0x00a83880 -[NSObject performSelector:withObject:withObject:] + 77
33 UIKit 0x0151d3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
34 UIKit 0x0151d345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
35 UIKit 0x0161ebd1 -[UIControl sendAction:to:forEvent:] + 66
36 UIKit 0x0161efc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
37 UIKit 0x0161e243 -[UIControl touchesEnded:withEvent:] + 641
38 UIKit 0x0155cddd -[UIWindow _sendTouchesForEvent:] + 852
39 UIKit 0x0155d9d1 -[UIWindow sendEvent:] + 1117
40 UIKit 0x0152f5f2 -[UIApplication sendEvent:] + 242
41 UIKit 0x01519353 _UIApplicationHandleEventQueue + 11455
42 CoreFoundation 0x0102b77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
43 CoreFoundation 0x0102b10b __CFRunLoopDoSources0 + 235
44 CoreFoundation 0x010481ae __CFRunLoopRun + 910
45 CoreFoundation 0x010479d3 CFRunLoopRunSpecific + 467
46 CoreFoundation 0x010477eb CFRunLoopRunInMode + 123
47 GraphicsServices 0x03ae75ee GSEventRunModal + 192
48 GraphicsServices 0x03ae742b GSEventRun + 104
49 UIKit 0x0151bf9b UIApplicationMain + 1225
50 eOpenRoad 0x00051e3d main + 141
51 libdyld.dylib 0x036b76d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
From provided log I can say that problem lie in [ContentDocumentsVC viewWillAppear:] where you set color to navigation bar with category method setNavigationBarControllerToHexColor: but looks like you call this method on wrong controller.

How to add an SKNode to an SKScene

When I enter this line in initWithSize:Size
[self addChild:world];
I retrive an error Thread 1:signal SIGABRT
world is an SKNode
The children that should be in world are also SKNode's
What am I doing wrong here as when I add the SKNode to the scene I retrieve an error
initWithSize:Size Method:
-(id)initWithSize:(CGSize)size{
if (self = [super initWithSize:size]){
//self.size = CGSizeMake(2048, 1048);
self.backgroundColor = [SKColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
_character = [self createCharacter];
[self addChild:_character];
[self addChild:world];
[self createChunks];
[world addChild:_character];
NSLog(#"Children in world: %#",[world children]);
}
return self;
}
createChunks: Method:
-(void)createChunks{
ProceduralMapGeneration *procedure = [[ProceduralMapGeneration alloc]init];
[procedure allocArrays];
_chunkOne = [procedure createChunk];
_chunkOne.position = CGPointMake(self.scene.size.width/2, self.scene.size.height/2);
[world addChild:_chunkOne];
_chunkTwo = [procedure createChunk];
_chunkTwo.position = CGPointMake(400,200);
[world addChild:_chunkTwo];
}
create chunks adds the chunks to world
world is created here
#implementation MainGame{
SKNode *world;
SKSpriteNode *_character;
SKNode *_chunkOne;
SKNode *_chunkTwo;
ProceduralMapGeneration *categoryBitManager;
}
Stack Trace
*** First throw call stack:
(
0 CoreFoundation 0x019161e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x016958e5 objc_exception_throw + 44
2 CoreFoundation 0x01915fbb +[NSException raise:format:] + 139
3 SpriteKit 0x0117cfca -[SKNode addChild:] + 175
4 Giraffe Rampage 0x0000289d -[MainGame initWithSize:] + 413
5 SpriteKit 0x0115ca09 +[SKScene sceneWithSize:] + 104
6 Giraffe Rampage 0x0000555d -[MainMenu touchesBegan:withEvent:] + 429
7 SpriteKit 0x0116e2bf -[SKView touchesBegan:withEvent:] + 824
8 UIKit 0x00274c0b -[UIWindow _sendTouchesForEvent:] + 386
9 UIKit 0x002759d1 -[UIWindow sendEvent:] + 1117
10 UIKit 0x002475f2 -[UIApplication sendEvent:] + 242
11 UIKit 0x00231353 _UIApplicationHandleEventQueue + 11455
12 CoreFoundation 0x0189f77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
13 CoreFoundation 0x0189f10b __CFRunLoopDoSources0 + 235
14 CoreFoundation 0x018bc1ae __CFRunLoopRun + 910
15 CoreFoundation 0x018bb9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x018bb7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x0390a5ee GSEventRunModal + 192
18 GraphicsServices 0x0390a42b GSEventRun + 104
19 UIKit 0x00233f9b UIApplicationMain + 1225
20 Giraffe Rampage 0x00005e6d main + 141
21 libdyld.dylib 0x01f5d701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
[self addChild:_character];
...
[world addChild:_character];
You added _character twice.

Crashing with custom navigation controller

I ran into an issue when testing my application in iOS7. The application currently runs just fine in iOS5 and iOS6. Based on the stack trace, it would appear that a private method is causing the issue.
2013-11-21 17:00:56.565 MyApp[706:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An override of -[UINavigationController navigationBar] is returning an object that is not a kind of UINavigationBar'
*** First throw call stack:
(
0 CoreFoundation 0x0244d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01eee8b6 objc_exception_throw + 44
2 CoreFoundation 0x0244d3bb +[NSException raise:format:] + 139
3 UIKit 0x00af796c -[UINavigationController _confirmBarAccessMethods] + 277
4 UIKit 0x00af7b19 -[UINavigationController initWithNibName:bundle:] + 271
5 MyApp 0x000b8bd8 -[CustomUINavigationController initWithNibName:bundle:] + 152
6 UIKit 0x00af77b3 -[UINavigationController initWithRootViewController:] + 86
7 MyApp 0x000b8ea1 -[CustomUINavigationController initWithRootViewController:] + 113
8 MyApp 0x0000260a -[AppDelegate application:didFinishLaunchingWithOptions:] + 666
9 UIKit 0x009c7355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
10 UIKit 0x009c7b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
11 UIKit 0x009cc3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
12 UIKit 0x009e087c -[UIApplication handleEvent:withNewEvent:] + 3447
13 UIKit 0x009e0de9 -[UIApplication sendEvent:] + 85
14 UIKit 0x009ce025 _UIApplicationHandleEvent + 736
15 GraphicsServices 0x0478b2f6 _PurpleEventCallback + 776
16 GraphicsServices 0x0478ae01 PurpleEventCallback + 46
17 CoreFoundation 0x023c8d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
18 CoreFoundation 0x023c8a9b __CFRunLoopDoSource1 + 523
19 CoreFoundation 0x023f377c __CFRunLoopRun + 2156
20 CoreFoundation 0x023f2ac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x023f28db CFRunLoopRunInMode + 123
22 UIKit 0x009cbadd -[UIApplication _run] + 840
23 UIKit 0x009cdd3b UIApplicationMain + 1225
24 MyApp 0x00002337 main + 295
25 MyApp 0x00002205 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This crash happens only when testing in iOS7. It happens as soon as [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil] is called. I cannot find any information about _confirmBarAccessMethods. I assume it is a private UINavigationController method.
Here is the header file for the CustomUINavigationController class:
#import <UIKit/UIKit.h>
#import "CustomUINavigationBar.h"
#interface CustomUINavigationController : UINavigationController
{
CustomUINavigationBar *customNavigationBar;
}
#property (nonatomic, retain) UIColor *titleColor;
#end
This is the init method in which the application crashes:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; // This line causes the application to crash
if (self) {
customNavigationBar = [[CustomUINavigationBar alloc] init];
[customNavigationBar setTintColor:[UIColor colorWithWhite:0.0 alpha:1.0]];
[customNavigationBar setItems:[NSArray array] animated:NO];
[customNavigationBar setDelegate:self];
self.titleColor = [UIColor colorWithWhite:1.0 alpha:1.0];
}
return self;
}
Here is the header file for CustomNavigationBar:
#import <UIKit/UIKit.h>
#interface CustomUINavigationBar : UINavigationBar
{
UIImage *background;
}
#end
Any help would be greatly appreciated. I can provide more information if necessary.
EDIT: Added trace from suggested solution of using custom navigation bar initializer
2013-11-22 13:04:49.756 MyApp[390:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An override of -[UINavigationController navigationBar] is returning an object that is not a kind of UINavigationBar'
*** First throw call stack:
(
0 CoreFoundation 0x0244d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01eee8b6 objc_exception_throw + 44
2 CoreFoundation 0x0244d3bb +[NSException raise:format:] + 139
3 UIKit 0x00af796c -[UINavigationController _confirmBarAccessMethods] + 277
4 UIKit 0x00af7b19 -[UINavigationController initWithNibName:bundle:] + 271
5 MyApp 0x000b8e38 -[CustomUINavigationController initWithNibName:bundle:] + 152
6 UIKit 0x00af7815 -[UINavigationController initWithNavigationBarClass:toolbarClass:] + 52
7 MyApp 0x00002868 -[AppDelegate application:didFinishLaunchingWithOptions:] + 712
8 UIKit 0x009c7355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
9 UIKit 0x009c7b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
10 UIKit 0x009cc3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
11 UIKit 0x009e087c -[UIApplication handleEvent:withNewEvent:] + 3447
12 UIKit 0x009e0de9 -[UIApplication sendEvent:] + 85
13 UIKit 0x009ce025 _UIApplicationHandleEvent + 736
14 GraphicsServices 0x0478b2f6 _PurpleEventCallback + 776
15 GraphicsServices 0x0478ae01 PurpleEventCallback + 46
16 CoreFoundation 0x023c8d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
17 CoreFoundation 0x023c8a9b __CFRunLoopDoSource1 + 523
18 CoreFoundation 0x023f377c __CFRunLoopRun + 2156
19 CoreFoundation 0x023f2ac3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x023f28db CFRunLoopRunInMode + 123
21 UIKit 0x009cbadd -[UIApplication _run] + 840
22 UIKit 0x009cdd3b UIApplicationMain + 1225
23 MyApp 0x00002567 main + 295
24 MyApp 0x00002435 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Create the navigation controller with initWithNavigationBarClass:toolbarClass: and supply your custom navigation bar class. Then perform any configuration you require on the instance created for you by the nav controller superclass.
I finally resolved the issue. CustomerUINavigationController had an override method for the navigationBar accessor. It was attempting to return a nil value. I removed this and the application compiled and ran with no issues.

UIAlertView crashes in iOS7

We had compiled and deployed an app in iOS 6 environment. But, now the app is getting crash in iOS 7 whenever showing an alert.
App simply getting crash in [alertView show];
But, the same app is running perfect in iOS 6.
Code for showing alert
-(void)displayAlertWithMessage:(NSString *)message withTitle:(NSString *)title andTag:(int)tag
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
and calling like this
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:nil andTag:1];
Here, is the crash log.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/developer/Library/Application Support/iPhone Simulator/7.0/Applications/A0BCB945-8E4A-4D06-BEE8-240FF45ECF78/MyProject.app> (loaded)' with name '_UIModalItemAppViewController''
*** First throw call stack:
(
0 CoreFoundation 0x003176f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027c88b6 objc_exception_throw + 44
2 CoreFoundation 0x003174cb +[NSException raise:format:] + 139
3 UIKit 0x015d1bec -[UINib instantiateWithOwner:options:] + 951
4 UIKit 0x01444f05 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
5 UIKit 0x014456ad -[UIViewController loadView] + 302
6 UIKit 0x014459ae -[UIViewController loadViewIfRequired] + 78
7 UIKit 0x01445eb4 -[UIViewController view] + 35
8 UIKit 0x018dc9da -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibilityCreateIfNeeded:] + 248
9 UIKit 0x018dc8dd -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibility] + 41
10 UIKit 0x01812801 -[UIAlertView(Private) popupAlertAnimated:animationType:atOffset:] + 382
11 UIKit 0x01812c1d -[UIAlertView(Private) popupAlertAnimated:animationType:] + 56
12 UIKit 0x01817c17 -[UIAlertView showWithAnimationType:] + 48
13 UIKit 0x01817c45 -[UIAlertView show] + 41
14 MyProject 0x000330a8 -[LoginViewController displayAlertWithMessage:withTitle:andTag:] + 232
15 MyProject 0x00032e8b -[LoginViewController isValidContent] + 299
16 MyProject 0x00033136 -[LoginViewController showSetPinView] + 54
17 libobjc.A.dylib 0x027da874 -[NSObject performSelector:withObject:withObject:] + 77
18 UIKit 0x0133524c -[UIApplication sendAction:to:from:forEvent:] + 108
19 UIKit 0x013351d8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
20 UIKit 0x0142ba5d -[UIControl sendAction:to:forEvent:] + 66
21 UIKit 0x0142be20 -[UIControl _sendActionsForEvents:withEvent:] + 577
22 UIKit 0x0142b0cf -[UIControl touchesEnded:withEvent:] + 641
23 UIKit 0x0137221d -[UIWindow _sendTouchesForEvent:] + 852
24 UIKit 0x01372e84 -[UIWindow sendEvent:] + 1232
25 UIKit 0x01346b86 -[UIApplication sendEvent:] + 242
26 MyProject 0x000c2c75 -[Application sendEvent:] + 101
27 UIKit 0x0133135f _UIApplicationHandleEventQueue + 11421
28 CoreFoundation 0x002a096f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x002a02fb __CFRunLoopDoSources0 + 235
30 CoreFoundation 0x002bd3ce __CFRunLoopRun + 910
31 CoreFoundation 0x002bcbf3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x002bca0b CFRunLoopRunInMode + 123
33 GraphicsServices 0x036f0a27 GSEventRunModal + 192
34 GraphicsServices 0x036f084e GSEventRun + 104
35 UIKit 0x01333f0b UIApplicationMain + 1225
36 MyProject 0x00006612 main + 178
37 MyProject 0x00006555 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks in advance.
As per crash log it says to me "[UIViewController _loadViewFromNibNamed:bundle:]" unable to load nib file.
But, in my project I had created a category for UIViewController class and overridden the -(id)init method. Upto ios6, while showing an alert this category method is not at all executing, but from ios7 onwards overridden init() method of UIViewController.
So, I fixed this issue by adding the another validation in UIViewController category's init() method for checking the class method is UIAlertView or not, if it is UIAlertView then simply calling [super init]; instead of doing my other stuff relating to view controllers.
Sample code:
- (id)init
{
NSString *viewControllerName = [NSString stringWithFormat:#"%#",[self class]];
if([viewControllerName isEqualToString:#"UIAlertView"])
{
self = [super init];
}
else
{
// my stuff
}
return self;
}
you can test it.. try to avoid nil.. instead of that put something... like
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:#"Hello" andTag:1]
and you need to release alert view so in function write release code...

Why am I getting invalidArgument exception while running unit test?

Inside my Table view controller I have following method
-(BOOL)isValidCoordinate:(CLLocationCoordinate2D)coordinate
{
//This is just to make sure exception is always thrown a cut down version of method
[NSException raise:#"Invalid longitude value" format:#"Longitude of %d is invalid", coordinate.longitude];
return TRUE;
}
I am running a unit test against it and I it failing giving following exception
2011-10-04 22:58:43.380 navman2[74159:ec03] -[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830
2011-10-04 22:58:43.382 navman2[74159:ec03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f555a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010a9313 objc_exception_throw + 44
2 CoreFoundation 0x00f570bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ec6966 ___forwarding___ + 966
4 CoreFoundation 0x00ec6522 _CF_forwarding_prep_0 + 50
5 navman2Tests 0x05765b41 -[navman2Tests testExceptionThrownBycoordinatesCheck] + 193
6 CoreFoundation 0x00ec5c7d __invoking___ + 29
7 CoreFoundation 0x00ec5b51 -[NSInvocation invoke] + 145
8 SenTestingKit 0x201043d2 -[SenTestCase invokeTest] + 69
9 SenTestingKit 0x20104aa7 -[SenTestCase performTest:] + 192
10 SenTestingKit 0x201041d3 -[SenTest run] + 88
11 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
12 SenTestingKit 0x201041d3 -[SenTest run] + 88
13 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
14 SenTestingKit 0x201041d3 -[SenTest run] + 88
15 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
16 SenTestingKit 0x201041d3 -[SenTest run] + 88
17 SenTestingKit 0x201067a4 +[SenTestProbe runTests:] + 174
18 Foundation 0x0092e79e __NSFireDelayedPerform + 441
19 CoreFoundation 0x00f368c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
20 CoreFoundation 0x00f37e74 __CFRunLoopDoTimer + 1220
21 CoreFoundation 0x00e942c9 __CFRunLoopRun + 1817
22 CoreFoundation 0x00e93840 CFRunLoopRunSpecific + 208
23 CoreFoundation 0x00e93761 CFRunLoopRunInMode + 97
24 GraphicsServices 0x016171c4 GSEventRunModal + 217
25 GraphicsServices 0x01617289 GSEventRun + 115
26 UIKit 0x001b5c93 UIApplicationMain + 1160
27 navman2 0x000028b9 main + 121
28 navman2 0x00002835 start + 53
)
terminate called throwing an exception(gdb)
Unit test is following:
#import "navman2Tests.h"
#import "TableViewController.h"
#import "MapViewController.h"
#implementation navman2Tests
- (void)setUp
{
[super setUp];
// Set-up czode here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void) testExceptionThrownBycoordinatesCheck
{
TableViewController *newView2 =[[MapViewController alloc] init];
CLLocationCoordinate2D coordinate;
double lat = 61.2180556;
double lng = -149.9002778;
coordinate.latitude = lat;
coordinate.longitude = lng;
STAssertThrows([newView2 isValidCoordinate:coordinate],#"some text description");
[newView2 release];
}
#end
The error is that you did declare newView2 as a TableViewController not a MapViewController (which has that method), change:
TableViewController *newView2 =[[MapViewController alloc] init];
with:
MapViewController *newView2 =[[MapViewController alloc] init];
anyway I would call the variable newViewController rather than newView2 :P