From f11e4fe5a2782704b3a1975ceaf91061cb727398 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 19 Feb 2018 16:57:40 +0300 Subject: [PATCH] [MAPSME-6511] [ios] Updated UITableView extensions. --- .../Maps/Categories/UITableView+Cells.swift | 20 +++++++++++++ .../Maps/Categories/UITableView+Updates.swift | 28 +++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/iphone/Maps/Categories/UITableView+Cells.swift b/iphone/Maps/Categories/UITableView+Cells.swift index 079ae1925f..d0e1e55342 100644 --- a/iphone/Maps/Categories/UITableView+Cells.swift +++ b/iphone/Maps/Categories/UITableView+Cells.swift @@ -10,4 +10,24 @@ extension UITableView { @objc func dequeueReusableCell(withCellClass cellClass: AnyClass, indexPath: IndexPath) -> UITableViewCell { return dequeueReusableCell(withIdentifier: toString(cellClass), for: indexPath) } + + func registerNib(cell: Cell.Type) where Cell: UITableViewCell { + register(UINib(cell), forCellReuseIdentifier: toString(cell)) + } + + func registerNibs(cells: [Cell.Type]) where Cell: UITableViewCell { + cells.forEach { registerNib(cell: $0) } + } + + func register(cell: Cell.Type) where Cell: UITableViewCell { + register(cell, forCellReuseIdentifier: toString(cell)) + } + + func dequeueReusableCell(cell: Cell.Type) -> Cell? where Cell: UITableViewCell { + return dequeueReusableCell(withIdentifier: toString(cell)) as? Cell + } + + func dequeueReusableCell(cell: Cell.Type, indexPath: IndexPath) -> Cell where Cell: UITableViewCell { + return dequeueReusableCell(withIdentifier: toString(cell), for: indexPath) as! Cell + } } diff --git a/iphone/Maps/Categories/UITableView+Updates.swift b/iphone/Maps/Categories/UITableView+Updates.swift index e76a84f76a..39d2d2541d 100644 --- a/iphone/Maps/Categories/UITableView+Updates.swift +++ b/iphone/Maps/Categories/UITableView+Updates.swift @@ -3,18 +3,28 @@ extension UITableView { typealias Completion = () -> Void @objc func update(_ updates: Updates) { - beginUpdates() - updates() - endUpdates() + if #available(iOS 11.0, *) { + performBatchUpdates(updates, completion: nil) + } else { + beginUpdates() + updates() + endUpdates() + } } @objc func update(_ updates: Updates, completion: @escaping Completion) { - CATransaction.begin() - beginUpdates() - CATransaction.setCompletionBlock(completion) - updates() - endUpdates() - CATransaction.commit() + if #available(iOS 11.0, *) { + performBatchUpdates(updates, completion: { _ in + completion() + }) + } else { + CATransaction.begin() + beginUpdates() + CATransaction.setCompletionBlock(completion) + updates() + endUpdates() + CATransaction.commit() + } } @objc func refresh() {