I am replacing a view inside a navigation controller with the setViewControllers-method.
But i dont like the look of the transition. How can i set the animation-style when using the following code ?
UIViewController *newVC = [self.storyboard instantiateViewControllerWithIdentifier:#"SuccessScreen"];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeLastObject];
[viewControllers addObject:newVC];
[[self navigationController] setViewControllers:viewControllers animated:YES];
Something like
CATransition *yourAnimation=...;
[self.navigationController.view.layer addAnimation:yourAnimation forKey:nil]
[[self navigationController] setViewControllers:viewControllers animated:NO];
Related
I have added pageviewController programmatically as follows. It works. However, when I try to remove with [self.pageViewController.view removeFromSuperview];, it does not remove it.
Adding pageViewController
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
Removing pageViewController
[self.pageViewController.view removeFromSuperview];
Use the below set of instructions to remove your pageViewController:
[self.pageViewController willMoveToParentViewController:nil];
[self.pageViewController.view removeFromSuperview];
[self.pageViewController removeFromParentViewController];
I have implemented MFSideMenu in my project .It works great, but now i want to implement back button facility to every view.
I try this but not working:
NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];
Here is the Solution
HomeView *Home = [[HomeView alloc]initWithNibName:#"HomeView" bundle:nil];
NSArray *controllers = [NSArray arrayWithObject:Home];
self.navigationController.viewControllers = controllers;
I have this code snippet in a view controller that conforms to UIPageViewControllerDataSource protocol:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *tempViewControllers = [[NSMutableArray alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:#"page1Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:#"page2Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:#"page3Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:#"page4Controller"]];
[tempViewControllers addObject:[storyboard instantiateViewControllerWithIdentifier:#"page5Controller"]];
self.pages = [NSArray arrayWithArray:tempViewControllers];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"pageViewController"];
self.pageViewController.dataSource = self;
Page1ViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
[self addChildViewController:self.pageViewController];
[self.containerView addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
[self.view bringSubviewToFront:self.headerView];
}
This is working when I run the app in iOS 8 and in iOS 9, but when I run it in iOS 7, I see in Xcode that the CPU reaches around 93% of workload, and the app gets blocked and unresponsive.
If I comment the call to [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; the app runs normally (but I need such call)...
What could be happening here?
I am making demo in which I have to remove some of viewControllers from the NavigationController, and for that I have implemented below code but it give me issue.
I have pushed VC1,VC2,VC3 and now I want to push VC4 and remove VC2...
ViewController4 *VC4=[[ViewController4 alloc]initWithNibName:#"ViewController4" bundle:nil];
[self.navigationController pushViewController:VC4 animated:YES];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
for(UIViewController *objVC in viewControllers)
{
if([objVC isKindOfClass:[ViewController2 class]])
{
[viewControllers removeObjectIdenticalTo:objVC];
}
}
self.navigationController.viewControllers =viewControllers ;
This code works fine with iOS8 but in iOS7 with VC2 also VC3 removes automatically when I press the back button in VC4.
Even if I put below code the controller automatically removes from stack.
ViewController4 *VC4=[[ViewController4 alloc]initWithNibName:#"ViewController4" bundle:nil];
[self.navigationController pushViewController:VC4 animated:YES];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
self.navigationController.viewControllers =viewControllers ;
Here is the fix, working fine in iOS7 and iOS8:
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
// Find the things to remove
NSMutableArray *toDelete = [NSMutableArray array];
for(UIViewController *objVC in viewControllers)
{
if([objVC isKindOfClass:[ViewController2 class]])
{
[toDelete addObject:objVC];
}
}
[viewControllers removeObjectsInArray:toDelete];
self.navigationController.viewControllers =viewControllers ;
ViewController4 *VC4=[[ViewController4 alloc]initWithNibName:#"ViewController4" bundle:nil];
[self.navigationController pushViewController:VC4 animated:YES];
so I'm trying to create an ibooks-like reader and I need to update the contents of the UIPageViewController dynamically after I get the data from the webservice. For a long series of reasons I have to instantiate it at the beginning and then update it when the data comes.
I'm creating it like this:
NSDictionary *options =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
forKey: UIPageViewControllerOptionSpineLocationKey];
self.pageController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options: options];
self.pageController.dataSource = self;
self.pageController.delegate = self;
[[self.pageController view] setFrame:[[self view] bounds]];
MovellaContentViewController *initialViewController = [self viewControllerAtIndex:0];
self.controllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:self.controllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
and then I just set self.controllers = newControllersArray;
I'm looking for something like reloadData for a UITableViewController, is there such a thing for UIPageViewController?
You have to send setViewControllers:direction:animated:completion: to the pageController again
and give it the first view controller to display:
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self viewControllerAtIndex:0]
]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
If viewControllerAtIndex:does not access self.controllers as I at first assumed, it should probably rather be
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self.controllers objectAtIndex:0]
]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
instead
The main problem was that the webview was intercepting all the user touches and therefore the UiPageViewController wasn't calling the delegate methods. Once set the webview to ignore user touch events everything started to work properly.