Xcode 7.0.1
Update:
The latest thing I tried was to break down creation of the UINavigationController thus:
self.viewController = [[ProjectsViewController alloc] initWithNibName:#"ProjectsViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] init];
[self.navigationController setViewControllers:#[self.viewController]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Doing this the crash is now on
[self.window makeKeyAndVisible];
but the trace is exactly the same.
I've also tried this with a vanilla ViewController by changing
[self.navigationController setViewControllers:#[[[UIViewController alloc] init]]];
Same result...
Original Post:
I have a crash which I am struggling to understand - Here is the lldb trace: Note the index of 2147483648
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 2147483648 beyond bounds [0 .. 2]'
*** First throw call stack:
(
0 CoreFoundation 0x035eaa94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03084e02 objc_exception_throw + 50
2 CoreFoundation 0x034f92ed -[__NSArrayM removeObjectAtIndex:] + 445
3 UIKit 0x018c20b2 -[UIView(Hierarchy) bringSubviewToFront:] + 260
4 UIKit 0x0193daeb -[UINavigationBar layoutSubviews] + 3692
5 UIKit 0x018d716b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 813
6 libobjc.A.dylib 0x03099059 -[NSObject performSelector:withObject:] + 70
7 QuartzCore 0x0096e60c -[CALayer layoutSublayers] + 144
8 QuartzCore 0x0096228e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
9 QuartzCore 0x00970b2c -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 44
10 UIKit 0x018c4dca -[UIView(Hierarchy) layoutBelowIfNeeded] + 1244
11 UIKit 0x01a117cf __74-[UINavigationController _positionNavigationBarHidden:edge:initialOffset:]_block_invoke + 36
12 UIKit 0x018caca6 +[UIView(Animation) performWithoutAnimation:] + 82
13 UIKit 0x01a1178d -[UINavigationController _positionNavigationBarHidden:edge:initialOffset:] + 922
14 UIKit 0x01a1194c -[UINavigationController _positionNavigationBarHidden:edge:] + 326
15 UIKit 0x01a12d5f -[UINavigationController _positionNavigationBarHidden:] + 49
16 UIKit 0x01a1104a -[UINavigationController setNavigationBar:] + 1224
17 UIKit 0x01a10a38 -[UINavigationController _navigationBarHiddenByDefault:] + 156
18 UIKit 0x01a10997 -[UINavigationController navigationBar] + 41
19 UIKit 0x01a17805 -[UINavigationController loadView] + 230
20 UIKit 0x019d3338 -[UIViewController loadViewIfRequired] + 138
21 UIKit 0x019d3cf1 -[UIViewController view] + 35
22 UIKit 0x01a22226 -[UINavigationController pushViewController:transition:forceImmediate:] + 615
23 UIKit 0x01a21e27 __54-[UINavigationController pushViewController:animated:]_block_invoke + 351
24 UIKit 0x01a21c83 -[UINavigationController pushViewController:animated:] + 786
25 UIKit 0x01a07be2 -[UINavigationController initWithRootViewController:] + 140
26 DELETIA 0x0012954e -[AppDelegate application:didFinishLaunchingWithOptions:] + 1214
This is a mature app which has been building and running for some time but in the current XCode the above happens.
As you can see there is a call to UINavigationController:initWithRootViewController - here is the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// deletia - non UIKit code
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.tintColor = [UIColor darkGrayColor];
self.viewController = [[ProjectsViewController alloc] initWithNibName:#"ProjectsViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
// deletia - but the app crashes on the above line
}
I have tried a few things after looking at some similar questions and
answers here on SO.
I've heard that this can happen if View controller-based status bar
appearance is set to YES in the Info.plist - so I've set that to NO /
YES
I've heard that some UIGestureRecognizers can cause issues - So I've examined the XIB and ensured that there are none effecting this view controller.
I've heard that if the root view controller isn't fully initialised
it can be problematic - so I've delayed the call to the
UINavigationController by 1 second
I've mis-trusted ProjectsViewController - so I've substituted it for
a vanilla UIViewController thus:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
Any insight much appreciated; either in what might be causing the issue or in a technique to debug that might throw some light on the issue.
I think that you are focusing on the wrong piece of code. As you mentioned, it crashes on the [self.window makeKeyAndVisible] line, however, what's probably causing the crash is the fact that this line causes the ProjectsViewController and the UINavigationController objects to load and be presented to the user. Looking at the crash log you posted, this is the part you should be investigating:
2 CoreFoundation 0x034f92ed -[__NSArrayM removeObjectAtIndex:] + 445
3 UIKit 0x018c20b2 -[UIView(Hierarchy) bringSubviewToFront:] + 260
4 UIKit 0x0193daeb -[UINavigationBar layoutSubviews] + 3692
You can see here that iOS attempts to layout the UINavigationBar's subviews and then to remove an object at an index that is probably NSNotFound (which would result in NSIntegerMax, which matches the index you mentioned in your crash log).
In order to further research the crash, I would recommend following these steps:
Replace your ProjectsViewController instance with a UIViewController instance without a custom .xib file. (I read in your original post that you have already tried this, but still, I would recommend doing this as the first step in order to eliminate additional issues, if there is more than one, on the way to fully resolving the crash). It's important to make sure that you are not using your .xib file at this point, as it may be what's causing the crash (if there are any mis-linked outlets or similar issues).
Does your navigation bar have any items displayed in it? Again, I noticed you mentioned in the comments that it doesn't, but I would double check to see if maybe there's a code section in which items are added to the bar under certain conditions and removed if they aren't met. This can cause the crash, if the items are attempted to be removed from an invalid index.
Try searching for places in your code that specifically call removeObjectAtIndex or any other NSMutableArray related call that may be called during the load and display process of your initial view controller. Add a breakpoint in these places to see if they are reached during the initial loading process. If so, try adding a test there to make sure that the index you are trying to remove an object from is larger than or equal to zero and is smaller than the array's size. That way, if index you are trying to access is NSNotFound it will at least not cause the app to crash (a good practice regardless of the current crash). If this ends up resolving the issue, you can then investigate the issue further and try to understand why the NSNotFound is actually received as the index and fix the issue logically.
I hope one of these steps can help identify and resolve your issue. Good Luck!
UINavigationController is a stack where you can only push and pop UIViewController. You should pass a UIViewController on initiating navigation controller. But if you don't know RootViewController then you can do like this.
self.viewController = [[ProjectsViewController alloc] initWithNibName:#"ProjectsViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] init];
[self.navigationController pushViewController:self.viewController animated:NO];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Related
I have a problem with objective-c code that handles openning camera to take a picture the code is injected as native code inside codename one
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
NSArray *mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage, nil];
imagePicker.mediaTypes = mediaTypes;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:imagePicker animated:YES completion:nil];
}else{
[self showAlert:#"No Camera Privilege On This Device"];
}
the problem is when the above code is executed on iOS-11 ,I get null pointer exception from codenameone without asking for camera permission unlike iOS-12
the code works perfectly
the permission are added in the codenamesettings
codename1.arg.ios.NSPhotoLibraryAddUsageDescription=The App uses the Photo Library to save Images downloaded from News
codename1.arg.ios.NSCameraUsageDescription=The App uses the Camera for Video Chat support
codename1.arg.ios.NSPhotoLibraryUsageDescription=The App uses the Photo Library to save Images downloaded from News
is there anything that can be done to handle the issue on iOS11
--exception stack-trace from simulator using Xcode9.2
2018-10-04 18:47:50.830359+0300 TestApplication[7630:35311] *** Assertion failure in -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/UIApplication.m:1709
2018-10-04 18:47:50.853277+0300 TestApplication[7630:35311] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread'
*** First throw call stack:
(
0 CoreFoundation 0x000000010da7312b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010d107f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010da782f2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000109d38d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000107ac692d -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] + 359
5 UIKit 0x0000000107b51ac9 +[UIWindow _synchronizeDrawingWithPreCommitHandler:] + 57
6 UIKit 0x00000001082cfb7b -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 99
7 UIKit 0x000000010872be9a -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1697
8 UIKit 0x0000000108734c8f __43-[UIInputWindowController setInputViewSet:]_block_invoke.1493 + 97
9 UIKit 0x0000000108724208 -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 46
10 UIKit 0x000000010873481b -[UIInputWindowController setInputViewSet:] + 1336
11 UIKit 0x000000010872b450 -[UIInputWindowController performOperations:withAnimationStyle:] + 50
12 UIKit 0x00000001082c8164 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1669
13 UIKit 0x00000001082bff4b -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 2163
14 UIKit 0x00000001082c9480 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 498
15 UIKit 0x0000000107c89130 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1233
16 UIKit 0x0000000107c8ae94 -[UIViewController _presentViewController:withAnimationController:completion:] + 4621
17 UIKit 0x0000000107c8d9a9 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 99
18 UIKit 0x0000000107c8e079 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 532
19 UIKit 0x0000000107c8d908 -[UIViewController _presentViewController:animated:completion:] + 181
20 UIKit 0x0000000107c8dc67 -[UIViewController presentViewController:animated:completion:] + 159
appreciate the help
Regards,
thanks for all of your help , the problem as stated was only on iOS11 , and the reason for that if I present any viewcontroller with animated:Yes and I changed how to call the view controller by adding the following code
dispatch_queue_t _serialQueue = dispatch_queue_create("x.y.z", DISPATCH_QUEUE_CONCURRENT);
dispatch_sync(_serialQueue, ^{
self.filePath=param;
[self showForm];
});
and the showForm : just take a copy of the old viewcontroller and present the new one like this [condition was used to wait for the camera to finish picking and saving the file to gallery] :
-(void)showForm{
condition = [[NSCondition alloc] init];
self.parentViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[self.parentViewController.view setUserInteractionEnabled:NO];
destinationViewController = [[ViewController alloc] initWithValues:self.filePath andCondition:condition andChoice:#"Camera"];
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:destinationViewController animated:NO completion:nil];
[condition lock];
[condition wait];
self.filePath = [(ViewController*)destinationViewController getImagePath];
[self.parentViewController.view setUserInteractionEnabled:YES];
[condition unlock];
}
I hope that would help any one who needs it
Regards,
The app work fine before iOS 11 update. After iOS 11 rollout, some user get this below crash but I cannot reproduce this in simulator iOS 11. Based on fabric.io, not all iOS 11 experiencing this, so far I only received from 22 crash report from 4 users. Need some help here, thanks.
Fatal Exception: NSRangeException
*** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 1]
Fatal Exception: NSRangeException
0 CoreFoundation 0x185b7fd38 __exceptionPreprocess
1 libobjc.A.dylib 0x185094528 objc_exception_throw
2 CoreFoundation 0x185b18c44 _CFArgv
3 CoreFoundation 0x185a48cc0 -[__NSArrayM removeObjectAtIndex:]
4 UIKit 0x18f1e4aa8 -[UIPickerView selectedRowInComponent:]
5 UIKit 0x18fa4a224 -[_UIDatePickerMode_Date _dateForYearRow:]
6 UIKit 0x18fa46dd8 -[_UIDatePickerMode dateForRow:inCalendarUnit:]
7 UIKit 0x18fa47a70 -[_UIDatePickerMode _updateSelectedDateComponentsWithNewValueInComponent:usingSelectionBarValue:]
8 UIKit 0x18fa47d18 -[_UIDatePickerMode selectedDateComponents]
9 UIKit 0x18fa3b370 -[_UIDatePickerView _updatedLastSelectedComponentsByValidatingSelectedDateWithLastManipulatedComponent:]
10 UIKit 0x18fa3a7e8 -[_UIDatePickerView _setDate:animated:forced:]
11 UIKit 0x18fa3ad24 -[_UIDatePickerView _setMode:]
12 UIKit 0x18fa3ae40 -[_UIDatePickerView setDatePickerMode:]
13 UIKit 0x18f4f51d8 -[UIDatePicker initWithCoder:]
14 UIKit 0x18f6bf588 UINibDecoderDecodeObjectForValue
15 UIKit 0x18f6bf2c0 -[UINibDecoder decodeObjectForKey:]
16 UIKit 0x18f51652c -[UIRuntimeConnection initWithCoder:]
17 UIKit 0x18f516d00 -[UIRuntimeEventConnection initWithCoder:]
18 UIKit 0x18f6bf588 UINibDecoderDecodeObjectForValue
19 UIKit 0x18f6bf700 UINibDecoderDecodeObjectForValue
20 UIKit 0x18f6bf2c0 -[UINibDecoder decodeObjectForKey:]
21 UIKit 0x18f5158a0 -[UINib instantiateWithOwner:options:]
22 UIKit 0x18f51d64c -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]
23 xxxxxxxxxxxxxxxxxxxxxxxxxx 0x1030445f0 -[VerifyAccountViewController viewDidLoad] (VerifyAccountViewController.m:47)
24 UIKit 0x18ef8fbfc -[UIViewController loadViewIfRequired]
25 UIKit 0x18efa8318 -[UIViewController __viewWillAppear:]
26 UIKit 0x18f114ee0 -[UINavigationController _startCustomTransition:]
27 UIKit 0x18f036e04 -[UINavigationController _startDeferredTransitionIfNeeded:]
28 UIKit 0x18f036a34 -[UINavigationController __viewWillLayoutSubviews]
29 UIKit 0x18f03695c -[UILayoutContainerView layoutSubviews]
30 UIKit 0x18ef8d000 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
31 QuartzCore 0x189b5d0b4 -[CALayer layoutSublayers]
32 QuartzCore 0x189b61194 CA::Layer::layout_if_needed(CA::Transaction*)
33 QuartzCore 0x189acff24 CA::Context::commit_transaction(CA::Transaction*)
34 QuartzCore 0x189af6340 CA::Transaction::commit()
35 UIKit 0x18f1f3744 _UIApplicationFlushRunLoopCATransactionIfTooLate
36 UIKit 0x18f8d2718 __handleEventQueueInternal
37 UIKit 0x18f8cb574 __handleHIDEventFetcherDrain
38 CoreFoundation 0x185b28358 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
39 CoreFoundation 0x185b282d8 __CFRunLoopDoSource0
40 CoreFoundation 0x185b27b60 __CFRunLoopDoSources0
41 CoreFoundation 0x185b25738 __CFRunLoopRun
42 CoreFoundation 0x185a462d8 CFRunLoopRunSpecific
43 GraphicsServices 0x1878d7f84 GSEventRunModal
44 UIKit 0x18eff3880 UIApplicationMain
45 xxxxxxxxxxxxxxxxxxxxxxxxxx 0x103090ee4 main (main.m:13)
46 libdyld.dylib 0x18556a56c start
this part of the program code
- (void)viewDidLoad {
[super viewDidLoad];
storyboard = [UIStoryboard storyboardWithName:#"FirstTimeSetup" bundle:nil];
dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setTimeZone:[NSTimeZone systemTimeZone]];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"DatePickerView" owner:self options:nil]; //here is (VerifyAccountViewController.m:47)
self.inputDatePicker = [[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
self.inputDatePicker = [nib objectAtIndex:0];
self.inputDatePicker.datePicker.datePickerMode =UIDatePickerModeDate;
self.inputDatePicker.delegate = self;
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:#"Skip" style:UIBarButtonItemStylePlain target:self action:#selector(skipAction:)];
self.navigationItem.rightBarButtonItem = item;
}
We saw the same issue in our app and were able to fix by setting the date picker's calendar type to 'Gregorian' BEFORE setting any other date picker property, e.g.
self.inputDatePicker = [[DatePickerView alloc] init...];
self.inputDatePicker.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]
self.inputDatePicker.datePicker.datePickerMode = UIDatePickerModeDate;
self.inputDatePicker.delegate = self;
We reproduced on an iOS11 iPhone 6S by changing the user's calendar to Buddhist.
For some reason the app would crash if we set the calendar AFTER setting the date picker mode... seems like an Apple bug to force devs to have to think about the order in which we set our properties.
Not a complete solution but if it's trying to remove an object at index 9223372036854775807, it's worth pointing out that isn't a random number its the maximum value a 64 bit integer can hold
So somewhere maybe it's caught in a loop, or something along those lines. If you haven't already, upload your .dysm file to Fabric and it will give you more informative crash reports (even from the reports you already have) with function names, variables etc so you can pinpoint it to code more accurately
First of all - why do u set property twice here?...
self.inputDatePicker = [[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
self.inputDatePicker = [nib objectAtIndex:0];
If you want to make sure that this property will be not nil, just check returned nib array and if it's empty do something else.
According to crash log your array is cleaned before u are trying to get some value from. So try to change
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"DatePickerView" owner:self options:nil]; //here is (VerifyAccountViewController.m:47)
self.inputDatePicker = [[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
self.inputDatePicker = [nib objectAtIndex:0];
to
self.inputDatePicker = [[[NSBundle mainBundle] loadNibNamed:#"DatePickerView" owner:self options:nil] firstObject];
if (self.inputDatePicker == nil) {
// do something or perhaps better to check you nib
}
About FirstObject.
Did u have a chance to check nib content. Is it contains requested view or it's empty? If empty check name of your xib file. I personally prefer to write name of xib in something like NSStringFromClass([self class]) - of cause this require same name for class and xib file, but less error prone.
You have wrong on setup view from nib. You can use my library or watch code how I adding components from xib.
RMNibLoadedView
I am following this guide to create simple iPhone app.
But when I try to launch it, it fails with unrecognized selector sent to instance Exception.
I did debugging, and failure occurs on this line:
masterController.bugs = bugs;
of method (didFinishLaunchingWithOptions).
That's my first app, so it should be something obvious.
The only changes that I did to code on tutorial: added #import <UIKit/UIKit.h>, because otherwise it does not allow code to be compiled.
Full method code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RWTScaryBugDoc *bug1 = [[RWTScaryBugDoc alloc] initWithTitle:#"Potato Bug" rating:4 thumbImage:[UIImage imageNamed:#"potatoBugThumb.jpg"] fullImage:[UIImage imageNamed:#"potatoBug.jpg"]];
RWTScaryBugDoc *bug2 = [[RWTScaryBugDoc alloc] initWithTitle:#"House Centipede" rating:3 thumbImage:[UIImage imageNamed:#"centipedeThumb.jpg"] fullImage:[UIImage imageNamed:#"centipede.jpg"]];
RWTScaryBugDoc *bug3 = [[RWTScaryBugDoc alloc] initWithTitle:#"Wolf Spider" rating:5 thumbImage:[UIImage imageNamed:#"wolfSpiderThumb.jpg"] fullImage:[UIImage imageNamed:#"wolfSpider.jpg"]];
RWTScaryBugDoc *bug4 = [[RWTScaryBugDoc alloc] initWithTitle:#"Lady Bug" rating:1 thumbImage:[UIImage imageNamed:#"ladybugThumb.jpg"] fullImage:[UIImage imageNamed:#"ladybug.jpg"]];
NSMutableArray *bugs = [NSMutableArray arrayWithObjects:bug1, bug2, bug3, bug4, nil];
UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
MasterViewController *masterController = [navController.viewControllers objectAtIndex:0];
masterController.bugs = bugs;
// Override point for customization after application launch.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
return YES;
}
Full stacktrace:
2015-01-19 10:06:10.489 ScaryBugs[6603:5904685] -[UINavigationController setBugs:]: unrecognized selector sent to instance 0x7d116690
2015-01-19 10:06:10.491 ScaryBugs[6603:5904685] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setBugs:]: unrecognized selector sent to instance 0x7d116690'
*** First throw call stack:
(
0 CoreFoundation 0x00951946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x005daa97 objc_exception_throw + 44
2 CoreFoundation 0x009595c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x008a23e7 ___forwarding___ + 1047
4 CoreFoundation 0x008a1fae _CF_forwarding_prep_0 + 14
5 ScaryBugs 0x000f65a8 -[AppDelegate application:didFinishLaunchingWithOptions:] + 1288
6 UIKit 0x00cfe97c -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 291
7 UIKit 0x00cff687 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2869
8 UIKit 0x00d02c0d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
9 UIKit 0x00d1b7d0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
10 UIKit 0x00d0181f -[UIApplication workspaceDidEndTransaction:] + 155
11 FrontBoardServices 0x032919de __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
12 FrontBoardServices 0x0329146f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
13 FrontBoardServices 0x032a3425 __31-[FBSSerialQueue performAsync:]_block_invoke + 26
14 CoreFoundation 0x008751c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
15 CoreFoundation 0x0086aad3 __CFRunLoopDoBlocks + 195
16 CoreFoundation 0x0086a238 __CFRunLoopRun + 936
17 CoreFoundation 0x00869bcb CFRunLoopRunSpecific + 443
18 CoreFoundation 0x008699fb CFRunLoopRunInMode + 123
19 UIKit 0x00d011e4 -[UIApplication _run] + 571
20 UIKit 0x00d048b6 UIApplicationMain + 1526
21 ScaryBugs 0x000f853d main + 141
22 libdyld.dylib 0x02cb7ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Debugger info, before failure:
UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
MasterViewController *masterController = [navController.viewControllers objectAtIndex:0];
The problem is here. The code assumes that the rootViewController of the window is a navigation controller, but it's probably actually your split view controller. You then request the first view controller held by this supposed-but-not-actual navigation controller, which is the navigation controller itself. Of course, the navigation controller doesn't have a bugs property, so assigning to it causes the exception.
What you probably want to do instead is get a reference to the split view controller's first view controller, then get the returned navigation controller's first view controller, which is your actual MasterViewController.
The setContentViewController method in UIPopoverController seems to be causing an app crash in iOS 8. Just wondering if anybody else also faced this issue in iOS 8. This works without any issue in iOS 7.
The error pointed in the exception seems to be misleading as it states that the setContentViewController should be called after presenting the popover
- (void)buttonPressed {
UIViewController *tableViewController = [UIViewController new];
if(_popover == nil){
_popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
[_popover presentPopoverFromRect:CGRectMake(self.textField.frame.size.width / 2, self.textField.frame.size.height / 1, 1, 1) inView:self.textField permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}else{
[_popover setContentViewController:tableViewController];
}
}
Here is Stack trace from the crash,
2014-09-11 16:48:39.904 iOS 8 Rotation[3969:67869] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController setContentViewController:animated:] can only be called after the popover has been presented.'
*** First throw call stack:
(
0 CoreFoundation 0x01c79df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01903a97 objc_exception_throw + 44
2 CoreFoundation 0x01c79d1d +[NSException raise:format:] + 141
3 UIKit 0x00b1946f -[UIPopoverPresentationController _setContentViewController:animated:] + 89
4 UIKit 0x009bb1b4 -[UIPopoverController setContentViewController:animated:] + 155
5 UIKit 0x009bb114 -[UIPopoverController setContentViewController:] + 48
6 iOS 8 Rotation 0x00046ca5 -[MianViewController buttonPressed] + 933
7 libobjc.A.dylib 0x019197cd -[NSObject performSelector:withObject:withObject:] + 84
8 UIKit 0x002ef79d -[UIApplication sendAction:to:from:forEvent:] + 99
9 UIKit 0x002ef72f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
10 UIKit 0x00422a16 -[UIControl sendAction:to:forEvent:] + 69
11 UIKit 0x00422e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
12 UIKit 0x0042209d -[UIControl touchesEnded:withEvent:] + 660
13 UIKit 0x0033faba -[UIWindow _sendTouchesForEvent:] + 874
14 UIKit 0x00340595 -[UIWindow sendEvent:] + 791
15 UIKit 0x00305aa9 -[UIApplication sendEvent:] + 242
16 UIKit 0x003158de _UIApplicationHandleEventFromQueueEvent + 20690
17 UIKit 0x002ea079 _UIApplicationHandleEventQueue + 2206
18 CoreFoundation 0x01b9d7bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
19 CoreFoundation 0x01b932cd __CFRunLoopDoSources0 + 253
20 CoreFoundation 0x01b92828 __CFRunLoopRun + 952
21 CoreFoundation 0x01b921ab CFRunLoopRunSpecific + 443
22 CoreFoundation 0x01b91fdb CFRunLoopRunInMode + 123
23 GraphicsServices 0x040cc24f GSEventRunModal + 192
24 GraphicsServices 0x040cc08c GSEventRun + 104
25 UIKit 0x002ede16 UIApplicationMain + 1526
26 iOS 8 Rotation 0x0004774d main + 141
27 libdyld.dylib 0x0224cac9 start + 1
28 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I just encountered this same error testing our app under iOS 8. In our case, I took the error message at face value and changed a pattern we had in a few places.
The pattern we had to change was:
(1) in our view controller's init, instantiate a popover controller instance.
(2) on some event, set the popover controller's contentViewController property to the desired vc.
(3) call presentPopoverFromRect on the popover controller
and we simply changed step (2) to re-instantiate the popover controller with the desired content vc as an init parameter and ceased setting the contentViewController property (as we're always doing it prior to presenting the popover).
I was experiencing this same issue and finally solved it.
I have two buttons, each one shows its own popover. I was reusing the same UIPopoverController to show both of them. The first click worked fine, but then if you clicked the other one the app crashed.
The way I solved it is create a new UIPopoverController on each click:
importImagePickerControlPopoverController=[[UIPopoverController alloc] initWithContentViewController:pickerController];
[importImagePickerControlPopoverController setDelegate:self];
switch(pickerType)
{
case UIImagePickerControllerSourceTypePhotoLibrary:
case UIImagePickerControllerSourceTypeSavedPhotosAlbum:
[importImagePickerControlPopoverController setPopoverContentSize:CGSizeMake(320, 300) animated:YES];
break;
case UIImagePickerControllerSourceTypeCamera:
[importImagePickerControlPopoverController setPopoverContentSize:CGSizeMake(640, 640) animated:YES];
break;
}
[importImagePickerControlPopoverController setContentViewController:pickerController];
Similar to #user3495742 solution:
-(void)testAndSetPopoverWithVc:(UIViewController*)vc {
if (popover4Menu) {
if ([popover4Menu isPopoverVisible]) {
[popover4Menu setContentViewController:vc animated:YES];
return;
} else {
popover4Menu=nil;
}
};
popover4Menu=[[UIPopoverController alloc] initWithContentViewController:vc];
popover4Menu.delegate=self;
}
Problem rises when reassigning a view controller to an existing popover.
Free and realloc popover before assigning new content view controller: this fixed for me.
I had the same issue and this is what fixed it for me.
Try This
- (void)buttonPressed{
UIViewController *tableViewController = [UIViewController new];
//Check if the popover is nil or not visible
if(_popover == nil || _popover.popoverVisible == false){
_popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
[_popover presentPopoverFromRect:CGRectMake(self.textField.frame.size.width / 2, self.textField.frame.size.height / 1, 1, 1) inView:self.textField permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}else{
[_popover setContentViewController:tableViewController];
}
}
You have already have the content view controller set:
_popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
↑
Here
So, why not just delete the line?:
[_popover setContentViewController:tableViewController];
That should work.
If popover is not visible when you are calling [_popover setContentViewController:tableViewController];, app will get crash.
Because this method should be called when popover is visible on the screen.
Make sure your popover is visible,
if(_popover != nil && [_popover isPopoverVisible] == YES)
{
[_popover setContentViewController:tableViewController];
}else
{
//create new popover object if _popover is nil or present it
}
[self.popover dismissPopoverAnimated:YES]; //in case it's already showing.
self.popover = nil; // N.B. this is not the same as popover = nil.
self.popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
[self.popover presentPopoverFromRect:CGRectMake(self.textField.frame.size.width /
2, self.textField.frame.size.height / 1, 1, 1) inView:self.textField
permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
You do not need to create new instance of UIPopoverController neither set new contentViewController property after you first present UIPopoverViewController. (it depends on how you dismiss you popoverController)
However contentViewController can't be changed before popoverController presentation.
To workaround check popoverController.contentViewController properties. If it is nil, set conntentViewController, otherwise just present popover.
If you want to change contentViewController do it after presentation: use setContentViewController:animated: method.
Check that popoverController.isPopoverVisible before call this method.
Add these two methods into your UIwebview main class.
add <UIPopoverPresentationControllerDelegate> in your webview interface.h class as well.
define .
#property (strong, nonatomic) UIPopoverPresentationController *pop;
then
#synthesize pop;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Assuming you've hooked this all up in a Storyboard with a popover presentation style
if ([segue.identifier isEqualToString:#"showPopover"]) {
UINavigationController *destNav = segue.destinationViewController;
pop = destNav.viewControllers.firstObject;
// This is the important part
UIPopoverPresentationController *popPC = destNav.popoverPresentationController;
popPC.delegate = self;
}
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
I have already created a navigation controller in another class with a root view controller(the login screen). When I hit the login button I want it to push to the dashboard view controller. Here is my code
- (IBAction)logInHit:(id)sender {
if (passWord == true) {
DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:#"DashBoardViewController" bundle:nil];
[self.navigationController pushViewController:dash animated:YES];
}
else if (passWord == false){
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:#"Incorrect Password"];
[alert setMessage:#""];
[alert setDelegate:self];
[alert addButtonWithTitle:#"Try Again"];
[alert show];
}
}
It works when it pops a view controller and it also works when it is not in the if statement but for some odd reason it breaks when using the code above. The alert view works fine! It is just the push! Please help!
In the App Delegate.h:
NavigationViewController *navView;
Here is the App Delegate (This creates an instance of the navigationController class that I made which is based off of the generic one):
LogInViewController *logInView = [[LogInViewController alloc] init];
navView = [[NavigationViewController alloc] initWithRootViewController:logInView];
[self.window addSubview:navView.view];
Here is the Log:
2014-03-06 22:15:43.552 TopOPPS REP APP[795:70b] Application windows are expected to have a root view controller at the end of application launch
2014-03-06 22:16:18.728 TopOPPS REP APP[795:70b] -[LogInViewController textEnded:]: unrecognized selector sent to instance 0x109412a90
2014-03-06 22:16:18.730 TopOPPS REP APP[795:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LogInViewController textEnded:]: unrecognized selector sent to instance 0x109412a90'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101890795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001015f3991 objc_exception_throw + 43
2 CoreFoundation 0x0000000101921bad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010188209d ___forwarding___ + 973
4 CoreFoundation 0x0000000101881c48 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001002570ae -[UIApplication sendAction:to:from:forEvent:] + 104
6 UIKit 0x0000000100257044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x000000010032b450 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x000000010085a6d5 -[UITextField _resignFirstResponder] + 256
9 UIKit 0x000000010037ee40 -[UIResponder resignFirstResponder] + 222
10 UIKit 0x000000010085a4de -[UITextField resignFirstResponder] + 114
11 UIKit 0x000000010029b888 -[UIView setUserInteractionEnabled:] + 285
12 UIKit 0x000000010087f7b5 -[_UIViewControllerTransitionContext _disableInteractionForViews:] + 194
13 UIKit 0x0000000100364ce5 -[UINavigationController pushViewController:transition:forceImmediate:] + 1038
14 TopOPPS REP APP 0x000000010000254a -[LogInViewController logInHit:] + 202
15 UIKit 0x0000000100257096 -[UIApplication sendAction:to:from:forEvent:] + 80
16 UIKit 0x0000000100257044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
17 UIKit 0x000000010032b450 -[UIControl _sendActionsForEvents:withEvent:] + 203
18 UIKit 0x000000010032a9c0 -[UIControl touchesEnded:withEvent:] + 530
19 UIKit 0x000000010028bc15 -[UIWindow _sendTouchesForEvent:] + 701
20 UIKit 0x000000010028c633 -[UIWindow sendEvent:] + 988
21 UIKit 0x0000000100265fa2 -[UIApplication sendEvent:] + 211
22 UIKit 0x0000000100253d7f _UIApplicationHandleEventQueue + 9549
23 CoreFoundation 0x000000010181fec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010181f792 __CFRunLoopDoSources0 + 242
25 CoreFoundation 0x000000010183b61f __CFRunLoopRun + 767
26 CoreFoundation 0x000000010183af33 CFRunLoopRunSpecific + 467
27 GraphicsServices 0x00000001039983a0 GSEventRunModal + 161
28 UIKit 0x0000000100256043 UIApplicationMain + 1010
29 TopOPPS REP APP 0x0000000100001d53 main + 115
30 libdyld.dylib 0x0000000101f1f5fd start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Ok I got it!
In the NIB file of "LogInViewController", you created an Action called "textEnded", and after that you removed that method, but not the reference from the NIB.
To fix this, go to the LogInViewController NIB to see the Interface Builder, click on your UITextFields, and look inside the Connections Inspector for the method "textEnded" on the Sent Events category. After that, click on the "X" icon to remove the reference.
See this image as a reference:
1st You have to set root view Controller in appDelegate like,
LogInViewController *loginVC = [[LogInViewController alloc] initWithNibName:#"LogInViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginVC];
self.window.rootViewController = navController;
I think you are not familiar with if condition.
You should write like this
- (IBAction)logInHit:(id)sender {
if (passWord ) {
DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:#"DashBoardViewController" bundle:nil];
[self.navigationController pushViewController:dash animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:#"Incorrect Password"];
[alert setMessage:#""];
[alert setDelegate:self];
[alert addButtonWithTitle:#"Try Again"];
[alert show];
}
}
i checked your code its working complete fine...
but you have to set below in your appDelegate method
LogInViewController *loginVC = [[LogInViewController alloc] initWithNibName:#"LogInViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginVC];
self.window.rootViewController = navController;
as per your Console Log i can say that
you created one method called -(IBAction)textEnd:(id)sender{} before and linked that method to anywhere to button or textfied and now you removed that method and you forget to remove that method link from file inpector...
just double check your link from file inspector that all methods are available or not...
i got same error when i create -(IBAction)textEnd:(id)sender{} method and linked to UITextfield to EditingDidEnd action from file inpector and than i remove method whole method from my .m file and i got same error on click of login button so check your all links are have availabled linked methods