How to navigate to Custom Page from UIScrollView

110 Views Asked by At

Github Link - https://github.com/dnlatt/iOS/tree/master/MobileDataUsage2

  1. I fetched data from Core Data and passed to MobileDataUsageViewController.swift.

let detailVC = segue.destination as! MobileDataDetailsViewController
        detailVC.selectedYear = year
        detailVC.years = years
        detailVC.coreDataYears = coreDataYears

  1. In that Page, I want to show all of the data in slider format.

 override func viewDidLoad() {
        super.viewDidLoad()
        pageControl.numberOfPages = coreDataYears.count
        pageControl.backgroundColor = .systemBlue
        pageControl.currentPage = 1
        scrollView.delegate = self
        
        pageControl.addTarget(self, action: #selector(pageControlDidChange(_:)) , for: .valueChanged)
        view.addSubview(scrollView)
        view.addSubview(pageControl)
        
    }

  1. How can I access the index of Core Data Array? E.g from table, if user select '2018' I need to navigate to page 2 and show the result from page 2. I can set the Page Number in Page View Control Event.

If I click on 2018 from the first screen, it's always navigate to 2019 Data Result. I want to set the correct page & navigate to correct page. How can I get the index of selectedYear: Year! from coreDataYears: [Year] = [] and navigate to correct page. I can set the variable in below parameter

pageControl.currentPage = 1

enter image description here

Now only showing 2019 result which is the first one.

enter image description here

  1. If I swipe around the page, it's always stuck on the bottom. How can I fix the UI layout in ? Also there is extra scroll on the UI.

enter image description here

1

There are 1 best solutions below

1
latt On

Githublink - https://github.com/dnlatt/iOS/tree/master/MobileDataUsage3

Solved this issue by refactoring the code with UIPageViewController. Details in above Github link.