How to navigate to a View Controller embedded in tab bar controller - ios

I have a viewControllerA embedded in a navigationController.From this viewControllerA I want to navigate to another viewControllerB which is embedded in a tabBarController.
So I have a setup like -
viewControllerB is embedded in a navigationController and then this is embedded in tabBarController.
In viewControllerA I have a button from where I want to push to viewControllerB.
This is what I am trying to do -
-(void)areaBtnClicked:(id)sender{
NSLog(#"btn clicked");
UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:#"tabController"];
[self.navigationController pushViewController:tbc animated:YES];
}
However the app is crashing with a error message as -
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

Are you sured, that your controller has that identifier "tabController" ?
Check your storyboard.

Well apparently deleting the app from simulator solved the problem.

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.

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

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!

iOS Go back to parent view controller

I'm using payal iOS SDK and i want to go back to parent view controller in the function sendCompletedPaymentToServer using :
[self.navigationController popViewControllerAnimated:YES]
and :
[self dismissViewControllerAnimated:YES completion:nil]
app crashed.
ParentViewcontroller can be different.
it happens when i click on pay button for the second time.
ERROR Log :
2016-03-07 11:49:52.212 Ova[7169:2862312] Unbalanced calls to begin/end appearance transitions for .
2016-03-07 11:50:02.525 Ova[7169:2862312] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(0x184915900 0x183f83f80 0x184891478 0x100145268 0x10014494c 0x100144ba4 0x10011a200 0x100116a9c 0x10010aafc 0x100150200 0x1010cdbf0 0x1010cdbb0 0x1010d3658 0x1848ccbb0 0x1848caa18 0x1847f9680 0x185d08088 0x189670d90 0x10006ec28 0x18439a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
You are using :
[self.navigationController popViewControllerAnimated:YES];
This will bring you back to view controller. If you want to navigate back to previous view controller,you should implement :
[self.navigationController popToRootViewControllerAnimated:YES];
Resolved by adding BOOL variable to test if payment success or not. And into viewWillAppear i use:
[self.navigationController popViewControllerAnimated:YES];
thanks for all.
We also had same issue while integrating PayU gateway. I suggest you to use Protocol Delegate method to present view controller in which you are loading Payal in its web view.
Let second view controller is the one in which you are loading Payal and First view controller is presenting second view controller.
1. In Second view controller declare protocol that will dismiss secondviewcontroller
#protocol DismissPayalDelegate <NSObject>
#required
-(void)dismissPayal:(id)viewcontroller;
#end
#interface secondviewcontroller : UIViewController
#property(strong, nonatomic) id < DismissPayalDelegate > delegate;
#end
in secondviewcontroller.m file synthesize delegate object.In first view controller, If you are using performSegeuWithIdentifier (to present 2nd vc i.e Payal) then use get instance of destinationviewController i.e secondviewcontroller.
set destinationviewcontrollerInstance.delegate = self;
In secondViewController's Success/Failure method write code to dismiss view controller
[delegate dismissPayal:self];<br><br>
It will dismiss instance of second view controller that was presented in performSegueWithIdentifier methodUse this logic, I hope it helps you a lot.

iOS: Presenting a UIViewController modally (form sheet/page sheet) over splitViewController

I have a UISplitViewController (is the rootViewController)
and a UIViewController, vc1.
I'm trying to present vc1 over my split view controller from the MasterViewController part:
vc1.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:vc1 animated:YES completion:nil];
this raises an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Application tried to present modally an active
controller <MasterViewController: 0x8c5dd30>.'
...and crashes.
Tried this:
[self.splitViewController presentViewController:vc1 animated:YES completion:nil];
This raises an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason:'Application tried to present modally an active
controller <UISplitViewController:0x8c7e3a0>.'
However, if i try it with the interface builder (segues), it works.
How do i present a view controller, modally (as pages sheet or form sheet), over a split view controller, programmatically?
You can tell the DetailView controller to show it. Something like this I suppose.
DetailVC *detailVC = [self.splitViewController.viewControllers objectAtIndex:1];
[detailVC presentViewController:vc1 animated:YES completion:nil];
I suppose the issue is that your master is presenting a detail view and that's why it can't present anything else, so you ask the detail view to do it for you.

Push segues can only be used by UINavigationController Error

Getting a weird error when attempting to do a "push" sequence on a UIViewController.
I have embeded two UINavigationControllers into a root UIViewController.
I am basically attempting to make it so when the > button is pressed it pushes to the "View Controller."
Any ideas why I am getting the following error?:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
This is my storyboard:
http://cl.ly/image/3K0s3J1U1A3W
I am getting to the RecordViewController like so:
RecordViewController *record = [self.storyboard instantiateViewControllerWithIdentifier:#"RecordView"];
[self presentViewController:record animated:YES completion:nil];
If you want to push view controllers to a presented view controller, then your presented view controller must be a UINavigationController. In your case, give the leftmost navigation controller an identifier (i.e RecordNavigationController) and convert your code to:
UINavigationController *recordNavigationController = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:#"RecordNavigationController"];
[self presentViewController:recordNavigationController animated:YES completion:nil];

Resources