Created
July 25, 2017 09:56
-
-
Save noppefoxwolf/bd3edf7c7d441195c7372969c76164e0 to your computer and use it in GitHub Desktop.
UITableViewの最後のセルのIndexPathを見つける ref: http://qiita.com/noppefoxwolf/items/05c4028d0c3fb6b44fef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITableView { | |
var lastIndexPath: IndexPath? { | |
guard let dataSource = dataSource else { return nil } | |
return dataSource.lastIndexPath(in: self) | |
} | |
} | |
extension UITableViewDataSource { | |
func lastIndexPath(in tableView: UITableView) -> IndexPath? { | |
guard let sectionCount = self.numberOfSections?(in: tableView) else { return nil } | |
let lastSection = sectionCount - 1 | |
let rowCountOfLastSection = self.tableView(tableView, numberOfRowsInSection: lastSection) | |
let lastRow = rowCountOfLastSection - 1 | |
return IndexPath(row: lastRow, section: lastSection) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment