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.
Related
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.
Short version of question: When I pop a custom UIViewController that is parent to a UIPageViewController off a navigation stack, the app crashes - why and what's the workaround? Longer description below:
I have a login screen that then pushes on top a customer UIViewController which itself is the parent of a UIPageViewController that presents a UIPageView in a section of the parent controller's view. Let's call this custom UIViewController B, which is parent to a UIPageViewController as I said. Here are the parent view controller's properties as declared in the .h file for view controller B:
#interface bjViewController : UIPageViewController <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageController;
#property (assign, nonatomic) NSInteger index;
#property (strong, nonatomic) UILabel *screenNumber;
#property UIPageControl *childPageControl;
#end
And here is the troublesome code in viewDidLoad for view controller B:
UIViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
If I comment this out, I can pop this view controller off the UINavigationController stack without a problem back to UIViewController A, but with these lines in, the app crashes when I navigate back to view controller A. However if I navigate back to A after popping something else on instead of B, there is no problem, so I'm fairly sure the crash has something to do with these lines I've pasted above.
What happens with the crash is that the app does re-present the view from A but then gives an NSException error without indicating where it's crashing (and I have NSLog in all my functions for that view controller - none of those functions are being executed).
Here's the error I get. Yes I do have a breakpoint for all exceptions but it just dumps to the #implementation line in the .m file for B, even as it's already presenting A. Here's the error it gives:
2015-04-21 10:08:14.958 [953:110883] -[UIView invalidatePageViewController]: unrecognized selector sent to instance 0x1655e940
2015-04-21 10:08:49.375 [953:110883] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView invalidatePageViewController]: unrecognized selector sent to instance 0x1655e940'
*** First throw call stack:
(0x26a0845f 0x3489ec8b 0x26a0d879 0x26a0b797 0x2693d008 0x2a4a08fb 0x2690effd 0x2692614d 0x348b8d5f 0x2a091e9d 0x2a4a0981 0x53e95 0x3489dda1 0x348a75f7 0x348a761b 0x2a225435 0x2a0921e9 0x2a4a0981 0x2a181cd7 0x34e45ae1 0x29f58e75 0x348b8d5f 0x2690effd 0x26928df3 0x348b8d5f 0x348b91a9 0x2691a139 0x269ccd1f 0x2691a3b1 0x2691a1c3 0x2df47201 0x29f8443d 0x7379d 0x34e2aaaf)
libc++abi.dylib: termina
Has anyone run into something like this? Can you tell me what I'm doing wrong? I understand the basics of NSException and NSInvalidArgumentException, but I don't even know what's being called/incorrectly called.
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];
I'm not entirely sure why I am getting this error. It occurs when I click the button on my FirstViewController:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController 1ButtonPress:]: unrecognized selector sent to instance 0x10954bbd0'
My FirstViewController has a button (1ButtonPress) which performs a segue with another ViewController which has a embed NavigationController (so in my storyboard, the segue is from FirstViewController to the NavigationController). On this segue, some data is transferred to the other ViewController by:
First.m
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"abc"]) {
UINavigationController *navController = [segue destinationViewController];
SecondViewController *BVC = (SecondViewController *)(navController.topViewController);
BVC.BLLImg = [UIImage imageNamed:#"SomeImage.jpg"];
BVC.BLLTitle = #"SomeText";
}
}
The segue has the identifier "abc" in storyboard. Looking around it, I believe it has something to do with an incorrect class, but everything on first inspection looks fine. Any other reason why I would be getting this error?
Let's go through the error you saw. It says that an unrecognized selector was sent to an instance of FirstViewController.
From what I deduce, you hooked up your button to your view controller, and removed the implementation from your view controller later, assuming that it'd remove the connection you earlier created from your button to your view controller. Unfortunately, that's not how it works. You need to remove the connection from the button too.
To do that, right click on your button in the storyboard, and remove the connection which says 1ButtonPress:.
Side note: You're doing too much for a beginner to understand. Please try going through the Cocoa world step by step. Also, read up this article to learn about how to name your methods and variables in a more easy-to-understand way.
Right-click the 1ButtonPress button in your Storyboard. Remove the action to 1ButtonPress:.
I am having a silly problem with opening another viewcontroller on a buttonclick.
On my viewcontroller on my storyboard, I have a button. When a users clicks on this button, a new viewcontroller should be opened. As far as I know, there are 2 ways to do this.
in code
on the storyboard itself
Both methods are not working for me.
First the problem with storyboards:
(source: livefilestore.com)
I have connected my mainViewController with a navigationController, and I have connected my button with my next view (for adding an item). However, when I run the program, I get the following error:
'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
I really don't understand this error, because the mainviewcontroller IS managed by a UINavigationController.
So, as this didn't work, I tried to handle it in code. I connected the buttonclick action to the mainViewController.h file and implemented it in the .m file.
This is the action method when a user clicks on the button:
- (IBAction)actionBtnAdd:(id)sender {
AddInventoryViewController *addinvController = [self.storyboard instantiateViewControllerWithIdentifier:#"AddInventoryViewController"];
[self presentViewController:addinvController animated:NO completion:nil];
}
The other viewcontroller is in the same storyboard, and the ID of the other viewcontroller is "AddInventoryViewController". This gives me the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
Anybody who know the problem? What would be the best approach to solve this?
Your navigation controller is not the initial view controller. Select your nav controller on storyboard, go into Attributes Inspector and select "Is Initial View Controller".
Make your navigation controller Initial View Controller.
Then create a push-segue from button to target controller.
Then you can use following method to make some adjustments before pushing:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"TargetSegue"]) {
TargetViewController *vc = segue.destinationViewController;
//vc.items = nil;
}
}
Update:
There are more options:
If your initial view controller is tabbar: Add segue from one of the tabs to navigation controller which contains your view controller.
If your initial view controller is another navigation controller:
Remove navigation controller which contains your view controller. Then add the segue between the thirdViewController and the source from which it is presented. The you can use push segue between the button and the target view controller.
If you want to do it programmatically:
Remove navigation controller which contains your view controller. Push the thirdViewController from your currently presented navigation controller. Push the targetViewController from buttonAction.
Hope it will help :)
In your Xcode .Click the storyboard on the left side and on top select Editor->EmbedIn->Navigation controller .It will automatically add your navigation controller to the first view controller .Then it would work
You have to set the Navigation controller as the first controller
See before the Navigation controller there is the storyboard starting arrow
Under your IBAction method instead of using
[self presentViewController:addinvController animated:NO completion:nil];
use this code and check
[self.navigationController pushViewController:addinvController animated:YES];