diff --git a/Sources/UIKit/UITableView-Extensions.swift b/Sources/UIKit/UITableView-Extensions.swift index 73ebea4..9c0a348 100644 --- a/Sources/UIKit/UITableView-Extensions.swift +++ b/Sources/UIKit/UITableView-Extensions.swift @@ -12,10 +12,28 @@ public extension UITableView { var sectionsIndexSet: IndexSet { return IndexSet(integersIn: 0.. contentOffset.y ? firstPath : secondPath + } + } -extension UITableView { +public extension UITableView { func reloadWithoutAnimation(){ CATransaction.begin() CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) @@ -23,3 +41,39 @@ extension UITableView { CATransaction.commit() } } + + +public extension UITableView { + func scrollToLastRow() { + let indexPath = IndexPath(row:0,section: 0) + self.scrollToRow(at: indexPath, at: .bottom, animated: true) + } + func scrollToFirstRow() { + let indexPath = IndexPath(row: 0, section: 0) + self.scrollToRow(at: indexPath, at: .top, animated: true) + } + func scrollToSelectedRow() { + let selectedRows = self.indexPathsForVisibleRows + if let selectedRow = selectedRows?[0] as NSIndexPath? { + self.scrollToRow(at: selectedRow as IndexPath, at: .middle, animated: true) + } + } + func scrollToHeader() { + self.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: true) + } + func removeEliminateExtraSeparators() { + self.tableFooterView = UIView(frame: .zero) + self.tableHeaderView = UIView(frame:.zero) + } + func registerCell(_ cellTypes:[AnyClass]) { + for cellType in cellTypes { + let typeString = String(describing: cellType) + let xibPath = Bundle(for: cellType).path(forResource: typeString, ofType: ".nib") + if xibPath == nil { + register(cellType, forCellReuseIdentifier: typeString) + } else { + register(UINib(nibName: typeString, bundle: nil), forCellReuseIdentifier: typeString) + } + } + } +}