Skip to content

Commit 8aa361f

Browse files
author
Vadym Markov
committed
Merge pull request #8 from hyperoslo/fix/direction-bug
Fix the direction from only going backwards
2 parents 12b1b33 + 76d3239 commit 8aa361f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Source/PagesController.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ import UIKit
3131

3232
delegate = self
3333
dataSource = self
34-
goto(startPage)
34+
goTo(startPage)
3535
}
3636
}
3737

3838
// MARK: Public methods
3939
extension PagesController {
4040

41-
public func goto(index: Int) {
42-
if index > -1 && index < pages.count {
41+
public func goTo(index: Int) {
42+
if index >= 0 && index < pages.count {
43+
let direction: UIPageViewControllerNavigationDirection = (index > currentIndex) ? .Forward : .Reverse
4344
let viewController = pages[index]
4445
currentIndex = index
4546
setViewControllers([viewController],
46-
direction: (index > currentIndex) ? .Forward : .Reverse,
47+
direction: direction,
4748
animated: true, completion: nil)
4849
if setNavigationTitle {
4950
title = viewController.title
@@ -52,11 +53,11 @@ extension PagesController {
5253
}
5354

5455
public func next() {
55-
goto(currentIndex + 1)
56+
goTo(currentIndex + 1)
5657
}
5758

5859
public func previous() {
59-
goto(currentIndex - 1)
60+
goTo(currentIndex - 1)
6061
}
6162

6263
public func add(viewControllers: [UIViewController]) {

0 commit comments

Comments
 (0)