I am trying to create a PageViewController with multiple horizontally-paging UITableViews inside. The UITableViews are stored in an array; I use the UIPageViewController setViewControllers method to add the very first object in the array to the PageVC:
[self.pageViewController setViewControllers:[self.tableViews objectAtIndex:0] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
Then I add the remaining UITableViews to the PageViewController by using the viewControllerBeforeViewController and viewControllerAfterViewController methods.
However the setViewControllers method is producing the following error:
-[UITableView count]: unrecognized selector sent to instance 0x7c347e00
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView count]: unrecognized selector sent to instance 0x7c347e00'
Why is this error happening?
You should have a look at the method first you are using here:
- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers
direction:(UIPageViewControllerNavigationDirection)direction
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion;
It says the parameters should be the viewControllers
Parameters:
viewControllers The view controller or view controllers to be
displayed.
So, you have to take a UIViewcontroller or UITableViewController.
Two problems.
You need to pass view controllers and not views to the page view controller. For each UITableView, you need a UITableViewController.
If you change your variable self.tableViews to self.tableViewControllers (with the UITableViewController you create for each UITableView) you're half way there.
The other problem is that the first parameter for setViewControllers should be an NSArray. (NSArray has a selector called count.)
Change your code to wrap the first table view in an array when you're adding it:
[self.pageViewController setViewControllers:#[ [self.tableViewControllers objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]
Related
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.
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.
I have a UIViewController call Parent, and I have a UIView subview within Parent. I want to add one of two different possible UIViewControllers, called A and B, as subviews of Parent. A is a UIViewController with a UITableView. I set the datasource and delegate of the UITableView in A to A.
I can then "successfully" add A to Parent, setting the data for A as follows:
AViewController *vc = (AViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"A"];
NSMutableArray *data = [#[#"foo",#"bar",#"baz"] mutableCopy];
vc.posts = data;
[self.container addSubview:vc.view];
By successful, I mean that I see the tableview with the correct data in the cells. Namely foo, bar, and baz as the rows.
My Problem: When I try to scroll the tableview, it crashes. When I try to select a cell, I get the following exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[_UIAppearanceCustomizableClassInfo
tableView:didSelectRowAtIndexPath:]: unrecognized selector sent to instance 0x78c64430'
Because the AViewController is declared locally in your code above, it is deallocated as soon as that code completes. So when you touch for scrolling/selection and the delegate/datasource methods are called, the delegate and datasource point to a completely different object (or none at all). Hence your crash.
Furthermore, when implementing customer container views you need to implement some code so both parent and child know. Take a look at "Implementing a Custom Container View Controller" in the Apple Docs:
[self addChildViewController:vc];
[self.container addSubview:vc.view];
[vc didMoveToParentViewController:self];
I believe the addChildViewController will also provide a strong reference from the parent to the child (vc), thereby preventing it from being deallocated. So the above code should fix the deallocation problem as well.
In my storyboard I have 2 views one master and one detail with list. I want to show detail view on master. When I add detail to master like that:
- (void)viewDidLoad
{
[super viewDidLoad];
tableViewController = [[TableViewController alloc] init];
[self addChildViewController:detailVC];
[self.view addSubview:detailVC.view];
}
I get crash like that:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Im sure that there is everything ok with my table viewController becouse when I set it to rootViewController there is everything ok. What I'm doing wrong?
Looks like its an issue with tableview delegate methods. In story board please use static cell for your table view controller and remove table view delegate methods or else implement all required table view delegate methods.
My app requires two separate split view controllers. First I created first split view controller that works fine , now added second split view controller but second split view controller causes crash.
in first split's master:
#property (nonatomic,strong) WODTutorialDetailsView *wods;
- (void)viewDidLoad
{
[super viewDidLoad];
//init detail instance
self.wods= (WODTutorialDetailsView *)[[self.splitViewController.viewControllers lastObject] topViewController];
[self populateTableview];
self.navigationItem.title = #"WODs";
}
in second split's master:
#property (nonatomic,strong) LogDetailViewController *wods;
- (void)viewDidLoad
{
[super viewDidLoad];
//init detail instance
self.wods= (LogDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
[self populateTableview];
self.navigationItem.title = #"WODs";
}
Error I get is:
-[LogDetailViewController topViewController]: unrecognized selector sent to instance 0x229c4f40
2013-02-01 15:12:10.625 WOD Log[2473:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LogDetailViewController topViewController]:
How can I make it work?
I have never heard of a good rational for this but Apple does say that a UISplitViewController should be the topmost UI Controller. Although this project is a bit old, its description is pretty clear in what it does:
Custom UISplitView which can be used with navigation based project.
Take a look:
https://github.com/palaniraja/cUISplitViewController