Github Link - https://github.com/dnlatt/iOS/tree/master/MobileDataUsage2
- 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
- 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)
}
- 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
Now only showing 2019 result which is the first one.
- 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.



Githublink - https://github.com/dnlatt/iOS/tree/master/MobileDataUsage3
Solved this issue by refactoring the code with UIPageViewController. Details in above Github link.