Skip to content

Commit

Permalink
Update PagerTabStripViewController.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Desgard committed Feb 9, 2018
1 parent ce3a003 commit 81f3b87
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/PagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
open override var shouldAutomaticallyForwardAppearanceMethods: Bool {
return false
}

// 这里是 default selector pager
open func setupDefaultViewController(at index: Int) {
guard currentIndex != index else { return }
guard isViewLoaded, !self.viewControllers.isEmpty else {
currentIndex = index
return
}
guard view.window != nil else {
let step = (currentIndex < index) ? 1 : -1
for subindex in stride(from: currentIndex+step, through: index, by: step) {
containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: subindex), y: 0), animated: false)
}
return
}
}

open func moveToViewController(at index: Int, animated: Bool = true) {
guard isViewLoaded && view.window != nil && currentIndex != index else {
Expand Down

4 comments on commit 81f3b87

@ninjadev106
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your solution, but it doesn't work.
I invoked the setupDefaultViewController(at : 1) in viewdidload, but nothing happened.
what else is needed?

@Desgard
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mobilewebstar Before the super.viewDidLoad() is worked. The time of being called is same as settings.style configure.

override func viewDidLoad() {
    setupDefaultViewController(at: selected)

    settings.style.xxxx = xxxx;
    super.viewDidLoad()
}

@ninjadev106
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! but it worked once. So I had to call the method in viewwillappear() again.
override func viewWillAppear() {
setupDefaultViewController(at: selected)
}

@bivant
Copy link

@bivant bivant commented on 81f3b87 Mar 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.