Uipageviewcontroller Setviewcontrollers, UIpagecontrol Not Showing Right Current Number

UIPageViewController setViewControllers, UIPageControl not showing right current number

ok, turned out that i misunderstood one delegate method

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
return [(IntroPageViewController *)[pageViewController.viewControllers firstObject] index];
}

Page Indicator out of sync swift

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
let vc = pageViewController.viewControllers!.first as! PageViewContentViewController

return vc.pageIndex
}

You must return pageIndex... pageViewController.viewControllers!.indexOf((pageViewController.viewControllers?.first)!)! won't return right index

UIPageControl Not Updating Even the value changed

The problem is these line :

NeedDetailsController.status.page = currentIndex
NeedController.changePage()

You can't set values like this. Try adding this if block in didFinishAnimating method and then access properties using parentController.

if let parentController = self.parent as? NeedDetailsController {
print("didFinishAnimating is getting called.")
}

Page View Controller does not show dots

From my understanding, this should be present by default as long as Navigation is set to Horizontal and Transition style is set to Scroll, but nothing is showing.

Your understanding is wrong.

Do not add a page control. It is built in. It will show up provided you implement these two methods:

func presentationCount(for pvc: UIPageViewController) -> Int {
func presentationIndex(for pvc: UIPageViewController) -> Int {

Unfortunately the built in page control dots are white, which makes them hard to see. Use UIAppearance proxy to fix that (typically in applicationDidFinishLaunching). For example:

let proxy = UIPageControl.appearance()
proxy.pageIndicatorTintColor = UIColor.red.withAlphaComponent(0.6)
proxy.currentPageIndicatorTintColor = .red
proxy.backgroundColor = .yellow

At least this way you'll see that the page control is present and can modify the details to suit.

Changing UIPageViewController's page programmatically doesn't update the UIPageControl

to update your UIPageControl indicator, you need to implement one data source method of UIPageViewController (the UIPageViewControllerDataSource method) :

-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController

This method is responsible for updating the page control indicator (when you use UIPageViewController). You only need to return the currentpage value in this method. The Method gets called by default when you use/make a call for setViewControllers on your custom UIPageViewController.

So the chunk of code that you need to write is:

- (void)scrollToNext
{
UIViewController *current = self.viewControllers[0];
NSInteger currentIndex = [self.model indexForViewController:current];
UIViewController *nextController = [self.model viewControllerForIndex:++currentIndex];
if (nextController) {
NSArray *viewControllers = @[nextController];
// This changes the View Controller and calls the presentationIndexForPageViewController datasource method
[self setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return currentIndex;
}

Hope this solves your problem. :)



Related Topics



Leave a reply



Submit