Skip to content

Commit

Permalink
Merge pull request #295 from TortugaPower/fix/chapter-scroll
Browse files Browse the repository at this point in the history
Add automatic scrolling to current chapter in ChaptersViewController
  • Loading branch information
GianniCarlo committed Dec 18, 2018
2 parents c542e6d + b9df9b4 commit b37406a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion BookPlayer/Player/ChaptersViewController.swift
Expand Up @@ -14,12 +14,22 @@ class ChaptersViewController: UITableViewController {

var currentChapter: Chapter!
var didSelectChapter: ((_ selectedChapter: Chapter) -> Void)?
var scrolledToCurrentChapter = false

override func viewDidLoad() {
super.viewDidLoad()

self.tableView.tableFooterView = UIView()
self.tableView.reloadData()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

guard !self.scrolledToCurrentChapter, let index = self.chapters.firstIndex(of: self.currentChapter) else { return }

self.scrolledToCurrentChapter = true
let indexPath = IndexPath(row: index, section: 0)
self.tableView.scrollToRow(at: indexPath, at: .top, animated: false)
}

@IBAction func done(_ sender: UIBarButtonItem?) {
Expand Down

0 comments on commit b37406a

Please sign in to comment.