Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created July 25, 2017 09:56
Show Gist options
  • Save noppefoxwolf/bd3edf7c7d441195c7372969c76164e0 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/bd3edf7c7d441195c7372969c76164e0 to your computer and use it in GitHub Desktop.
UITableViewの最後のセルのIndexPathを見つける ref: http://qiita.com/noppefoxwolf/items/05c4028d0c3fb6b44fef
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