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
How to Add Frameworks into the Swift Project
Disable iOS Reachability Swipe Gesture in iOS Game
Uibarbuttonitem Changing Title Not Working
Load Custom Error HTMLstring When Wkwebview Loadrequest Fails
How to Show Viewcontroller from a Non-Viewcontroller Helper Class
Paste Formatted Text, Not Images or HTML
Uiwindow? Does Not Have Member Named Bounds
Proper Sequence to Get Registration Token for Gcm Push Notification on iOS? Is Gcm Unreliable
Upgrading to Swfit 3: Cannot Override 'Init' Which Has Been Marked Unavailable
Replacement for Arkit in iOS10
How to Use Indexesofobjectspassingtest: in Swift
How to Programmatically Delete My Own iOS App
Camera Only Takes Pictures in Portrait Mode Swift
Segue from Uitableviewcell by Tapping on an Image Inside of Cell
iOS Add Button to Widget Extension