"Terminating app due to uncaught exception" getting crash when pushing view controller - ios

Terminating app due to uncaught exception 'NSInvalidArgumentException', > reason: '-[UIViewController setDicSelectListItem:]: unrecognized selector sent to instance 0x10981be30'
I tried comment parameter passing. also tried provide main storyboard.
Below is the code where app getting crash
BilingInfoVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"BilingInfoVC"];
vc.dicSelectListItem=_dicSelectListItem;
vc.serviceType=_serviceType;
vc.arrSelect_Addons = [arrTemp mutableCopy];
[self.navigationController pushViewController:vc animated:YES];
I want to pass parameters with instantiate view controller.

Check this:
Is vc really of class 'BilingInfoVC'? If you didn't assign it correctly in IB it's a standard view controller.
You may check it with
NSLog(#"Class: %#", [vc className]);
As second line right after instantination of vc.
Did you set the identifier correctly? A capital letter can make a difference!

Related

Issues with rootViewController and Home Screen Quick Actions

I have the below Objective-C code to launch my app with Home Screen Quick Actions:
- (void)applyShortcutItem:(UIApplicationShortcutItem *)shortcutItem
{
ViewController *rootViewController = (ViewController *)[self.window rootViewController];
NSLog(#"Here %# - %#", rootViewController, shortcutItem);
if([shortcutItem.type isEqualToString:#"LaunchMode0"])
{
[rootViewController setShortcutAction:LaunchMode0];
}
else if([shortcutItem.type isEqualToString:#"LaunchMode1"])
{
[rootViewController setShortcutAction:LaunchMode1];
}
}
However, I keep getting runtime errors (unrecognized selected sent to instance) when I try to launch with the quick actions. Notably, it's these two lines where the app seems to trip up:
[rootViewController setShortcutAction:LaunchMode0]; and [rootViewController setShortcutAction:LaunchMode1];
It doesn't seem to like the rootViewController. Technically, the initial View Controller is the Navigation Controller, however the app launches to my main view controller (the app only has two views, the main one, and an about page).
There is more code above that code in my project, but this is the part that's giving me the error-- but let me know if seeing the other code would help (I didn't want the post to be too code heavy).
Thanks so much!
EDIT: as requested, here is the complete NSLog.
2019-09-23 18:18:01.317271-0400 AppName[1719:200993] Here <UINavigationController: 0x108802200> - <UIApplicationShortcutItem: 0x282bd1500; type: Mode1Shortcut, title: Mode 1>
2019-09-23 18:18:01.321819-0400 AppName[1719:200993] -[UINavigationController setShortcutAction:]: unrecognized selector sent to instance 0x108802200
2019-09-23 18:18:01.323462-0400 AppName[1719:200993] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setShortcutAction:]: unrecognized selector sent to instance 0x108802200'
*** First throw call stack:
(0x2045aa98c 0x2037839f8 0x2044c71c8 0x231033220 0x2045b01d4 0x2045b1e6c 0x102c14af0 0x102c148ec 0x230ffdf90 0x2308cc468 0x2308cd150 0x2308cc224 0x2308d0f24 0x230c012b0 0x206f275d8 0x102fecc78 0x102ff0840 0x206f61040 0x206f60cdc 0x206f61294 0x20453c728 0x20453c6a8 0x20453bf90 0x204536ecc 0x2045367c0 0x20673779c 0x231007c38 0x102c076d0 0x203ffa8e0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The problem is this:
ViewController *rootViewController = (ViewController *)[self.window rootViewController];
But you have stated that the root view controller is a UINavigationController. You need to get your ViewController from the nav controller.
UINavigationController *rootViewController = (UINavigationController *)self.window.rootViewController;
ViewController *viewController = (ViewController *)rootViewController.topViewController;
Then update the rest of the code to work on viewController.

MainViewController pushViewController:animated:]: unrecognized selector sent to instance 0x1459e980

I'm trying to add a functionality to open a specific view controller on opening the notification on my iOS app. As I am new to iOS, I have a few doubts.
I have written the backend, which sends the promo id as a custom parameter. I am able receive the JSON object on XCode, read the ID as a NSString.
Now, I want to open the PromotionDetailViewController with the promotion id as the parameter.
What I have done up to now is,
PromotionDetailViewController *pVC = [[PromotionDetailViewController alloc] initWithPromotionID:promo_id[#"promo_id"]];
[(UINavigationController *)self.window.rootViewController pushViewController:pVC animated:YES];
[(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];
I am able to receive and read the promo ID in the AppDelegate.m file.
When I run the above code, I get the below error.
MainViewController pushViewController:animated:]: unrecognized
selector sent to instance 0x1459e980
Any help in the right direction is great! I do php and android, but Obj-C is quite different!
UPDATE
Changed the code to this:
PromotionDetailViewController *pvc = [[PromotionDetailViewController alloc] initWithPromotionID:promo_id[#"promo_id"]];
UINavigationController *promoNav =
[[UINavigationController alloc] initWithRootViewController:pvc];
self.window.rootViewController = promoNav;
Now the API call is successful, I am able to see the correct NAV bar, but the app crashes due to the below error:
Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty
array'
(UINavigationController *)self.window.rootViewController it seems that is not a UINavigationController.
To get the correct NavigationController you can do self.navigationController if 'self' is already a child controller of the navigation one.
In obj-c Unrecognized selector means that you are sending a message to an object that does not respond to that, since you are casting it manually with parenthesis, the compiler doesn't complain and thinks is actually a NavgiationController, but isn't.

Add Value to property on ViewController from AppDelegate

I have the following code:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController performSegueWithIdentifier:#"push_display_incomming_call" sender:self];
This shows me the ViewController I want to see correctly. But now I want to change the property's value of the ViewController is being Segue before it's shown, I'm Trying the following with no success.
incommingCallViewController *mainController = (incommingCallViewController*) tabBarController;
mainController.name.text = #"Eddwn Paz";
This is the stacktrace from xCode Console:
2014-07-10 16:46:09.413 mobile-app[9354:60b] -[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540
2014-07-10 16:46:09.414 mobile-app[9354:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540'
Assume that push_display_incomming_call segue presents IncommingCallViewController view controller as modal. So you should use code:
IncommingCallViewController *callVC =
(IncommingCallViewController *)tabBarController.presentedViewController;
callVC.name.text = #"Eddwn Paz";
Remarks:
You receive the error because you try to use tabBarController as instance of incommingCallViewController while it is instance of UITabBarController thus it does not have required name property.

crash passing parameter from one viewcontroller to another

I'm trying to pass parameter from one view controller to another, but application crashes with exception.
My code is this:
SelectedItemViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:nextView animated:YES completion:NULL];
And I have the following in my stack:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setM_selectedItemId:]: unrecognized selector sent to instance 0x9c765d0'
In your storyboard, the view controller with identifier SelectedItemViewID is a navigation controller, not a SelectedItemViewController. So, before you set m_selectedItemId you should access the navigation controllers root view controller (which should be your SelectedItemViewController).
I found solution here: instantiateViewControllerWithIdentifier and pass data
What should be done in case if you want to pass parameter to view controller via navigation controller:
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"];
SelectedItemViewController *nextView = navigationController.viewControllers[0];
nextView.m_selectedItemId = [NSNumber numberWithInt:777];
[self presentViewController:navigationController animated:YES completion:NULL];
When you select the view controller in your storyboard, is the class set to SelectedItemViewController?
Obviously you seem to have a #property ... m_selectedItemId (or at least setter method setM_selectedItemId) on SelectedItemViewController, otherwise your code wouldn't even compile. But it seems that [storyboard instantiateViewControllerWithIdentifier:#"SelectedItemViewID"] doesn't really return the expected SelectedItemViewController. Hence I have the feeling that you forgot to set the correct class name to SelectedItemViewController in your storyboard.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target

I'm new in iphone, I'm trying to open a view when pressing a button,
in my class "ReaderViewController" I wrote the following code:
- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)button
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
#if (READER_ENABLE_MAIL == TRUE) // Option
instantiateViewControllerWithIdentifier:#"searchView"];
if (printInteraction != nil) [printInteraction dismissAnimated:NO]; // Dismiss
SearchViewController *searchController = [self.storyboard instantiateViewControllerWithIdentifier:#"searchView"];
searchController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
searchController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:searchController animated:YES];
[searchController release];
#endif // end of READER_ENABLE_MAIL Option
}
I want when to open the view of this controller "SearchViewController" and in storyboard I gave the view of SearchViewController its identifier name "searchView"
but when I run, it gives me the following Exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <ReaderViewController: 0x6864930>.'
Any Help ??
Thanks in advanced.
There's no view controller with the identifier searchView in your storyboard, so the instantiation fails and the
instantiateViewControllerWithIdentifier:
method returns nil. Double check your Storyboard setup and also note that identifiers and names are generally case-sensitive, maybe you named your view controller SearchView and not searchView.
It also may be the case that
self.storyboard
itself isn't properly initialized or instantiated, and thus is nil.
Edit: so you were creating the storyboard from code, but in fact you weren't. The solution was to manually instantiate UIStoryboard.
As for your own comment, you'd better assign self.storyboard = Storyboard or you'll continue getting these errors...
It looks to me like self.storyboard is nil. This means every message you are passing to it results in nil also.

Resources