1
페이지간에 빠르게 스 와이프 할 때 가끔씩 중복 페이지가 나타납니다. 내 색인 계산이 잘못되었을 수도 있지만 모든 것을 시도하고 항상 동일하게 나타납니다.동적 DataSource 페이지가있는 UIPageViewController가 반복됩니다.
DetailedProfileViewController.swift
class DetailedProfileViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
var currentProfileIndex : Int?
var nextProfileIndex :Int?
var data: Main?
var mainPageView : UIPageViewController!
override func viewDidLoad() {
super.viewDidLoad()
let profile = ProfileViewController()
profile.profile = currentProfile()
let arraysOfViews = [profile]
mainPageView = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [:])
mainPageView.setViewControllers(arraysOfViews, direction: .forward, animated: true, completion: nil)
mainPageView.dataSource = self
mainPageView.delegate = self
addChildViewController(mainPageView)
view.addSubview(mainPageView.view)
mainPageView.didMove(toParentViewController: self)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
if currentProfileIndex == (data?.filteredProfiles.count)!-1 { return nil }
nextProfileIndex = abs((currentProfileIndex! + 1) % (data?.filteredProfiles.count)!)
let profile = ProfileViewController()
profile.profile = data?.filteredProfiles[nextProfileIndex!]
return profile
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
if currentProfileIndex == 0 { return nil }
nextProfileIndex = abs((currentProfileIndex! - 1) % (data?.filteredProfiles.count)!)
let profile = ProfileViewController()
profile.profile = data?.filteredProfiles[nextProfileIndex!]
return profile
}
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if completed == true {
currentProfileIndex = nextProfileIndex
}
}
}
그들 수백 될 수 있기 때문에 내가
나는 그것을받지 못했습니다. 처음에는 profile.index = 0으로 설정하고 Before와 After에서는 어떻게해야합니까? – HelloimDarius
이전과 이후에는'pageViewController : UIPageViewController'도 param으로 가지고 있습니다. 예를 들어, 10이면 이전 뷰 컨트롤러를 만들 때 9가되어야합니다 (11 이후). –
let profile = pageViewController like Sometring? ProfoileViewController? 나는 그렇게 할 수 없다? – HelloimDarius