iOS - Terminating app due to uncaught exception 'NSInternalInconsistencyException' - ios

Installed Xcode 7.1 Beta and tested my app on iOS 9.0 and got below error. I went thorough different questions here.
I am using IIViewDeckController for left menu and PullRefreshTableViewController. In app delegate I register to different notification and give webservice call to get data for view controllers of VC1(Menu1) and VC2(Menu2), both inherits PullRefreshTableViewController. VC1 is displayed at first. When user navigates to VC2 the view gets loaded with data pulled but crashes with below exception.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fa8c541eaf0 of class UIView was deallocated while key value observers were still registered with it. Current observation info: (
Context: 0x0, Property: 0x7fa8c1d1b470>
)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110d7df65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001107f5deb objc_exception_throw + 48
2 CoreFoundation 0x0000000110d7de9d +[NSException raise:format:] + 205
3 Foundation 0x000000010f6528c1 NSKVODeallocate + 294
4 libobjc.A.dylib 0x000000011080a0b8 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 488
5 CoreFoundation 0x0000000110c6b956 _CFAutoreleasePoolPop + 22
6 CoreFoundation 0x0000000110c9f8d1 __CFRunLoopRun + 2081
7 CoreFoundation 0x0000000110c9ee28 CFRunLoopRunSpecific + 488
8 GraphicsServices 0x00000001134e4ad2 GSEventRunModal + 161
9 UIKit 0x000000010e12eca1 UIApplicationMain + 171
10 SeeMyRadiology 0x000000010d0d507e SeeMyRadiology + 16510
11 libdyld.dylib 0x000000011126992d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
**NOTE:**Same code works on iPad without error

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:#"LeftSideMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self.viewDeckController;
}
OR
https://github.com/edgecase/ECSlidingViewController
Just in case unable to solve problem.

If your table is reloaded it's possible that you loose your views, I mean, they are deallocated. If there are some connections beetwen deallocated views and values somewhere it causes the crash. You need to stop observing values before deallocating in order to avoid crash. Check this scenerio.

This worked for me.
The problem was while pushing view over the IIViewDeckController.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UINavigationController *centerController = [[UINavigationController alloc] initWithRootViewController:appDelegate.viewController];
[appDelegate.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller)
{
appDelegate.viewDeckController.centerController = centerController;
}];
Thank you your input guys. :)

Related

Debugging UIKit crash [UINavigationController initWithRootViewController]

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];

Unrecognized selector sent to instance on array assignment

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.

setContentViewController method in popover iOS8 causes app crash

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;
}

PushViewController breaks my program when in if statement

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

UISegmentedControl unrecognized selector sent

I've a part of my application that show in a MapView the possibilty to change the map type.
UISegmentedControl *mapType = [[UISegmentedControl alloc] initWithItems:
#[NSLocalizedString(#"MapTypeStandardLabelText", #""),
NSLocalizedString(#"MapTypeHybridLabelText", #""),
NSLocalizedString(#"MapTypeSatelliteLabelText", #"")]];
[self.view addSubview:mapType];
_mapTypeSegmentedControl = mapType;
_mapTypeSegmentedControl.center = self.view.center;
CGRect segmentedFrame = _mapTypeSegmentedControl.frame;
segmentedFrame.origin.y = self.view.frame.size.height -
_mapTypeSegmentedControl.frame.size.height - 20;
_mapTypeSegmentedControl.frame = segmentedFrame;
_mapTypeSegmentedControl.selectedSegmentIndex = _selectedSegmentIndex;
[_mapTypeSegmentedControl addTarget:self
action:#selector(changeMapType:)
forControlEvents:UIControlEventValueChanged];
When I tried to press a new type of the map showed, I get the following error:
2014-03-05 12:12:51.524 iBlues Pocket[31057:70b] -[UISegmentedControl modalPresentationStyle]: unrecognized selector sent to instance 0x20497250
2014-03-05 12:12:51.528 iBlues Pocket[31057:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISegmentedControl modalPresentationStyle]: unrecognized selector sent to instance 0x20497250'
*** First throw call stack:
(
0 CoreFoundation 0x038355e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x032ff8b6 objc_exception_throw + 44
2 CoreFoundation 0x038d2903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0382590b ___forwarding___ + 1019
4 CoreFoundation 0x038254ee _CF_forwarding_prep_0 + 14
5 UIKit 0x00d048c3 -[UIViewController presentViewController:withTransition:completion:] + 232
6 UIKit 0x11c46f1f -[UIViewControllerAccessibility(SafeCategory) presentViewController:withTransition:completion:] + 71
7 UIKit 0x00d0661f -[UIViewController presentViewController:animated:completion:] + 130
8 iBlues Pocket 0x000a022d -[MapOptionsViewController changeMapType:] + 109
9 libobjc.A.dylib 0x0331181f -[NSObject performSelector:withObject:] + 70
...
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Can anyone help me?
The changeMapType: method:
- (void)changeMapType:(id)sender {
[self presentViewController:sender animated:NO completion:nil];
if (_delegate != nil) {
[_delegate didCompleteOptionsSelection:sender];
}
}
It gives error Because you are sending the UISegment object in presentViewController: method,
SO try self
UIViewController *vc =// Your viewController to present
[self presentViewController:vc animated:NO completion:nil];
And if it is in viewDidLoad than put it in viewDidAppear method.

Resources