From abf2d250a369600e4487031918b97ad14cd10a84 Mon Sep 17 00:00:00 2001 From: nghialv Date: Mon, 16 Feb 2015 17:57:59 +0900 Subject: [PATCH] reset insertedSectionRange after reloading --- Example/MYTableViewManager/ViewController.swift | 6 ++++++ Source/MYTableViewManager.swift | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Example/MYTableViewManager/ViewController.swift b/Example/MYTableViewManager/ViewController.swift index 13dbcbd..ffdb66d 100644 --- a/Example/MYTableViewManager/ViewController.swift +++ b/Example/MYTableViewManager/ViewController.swift @@ -61,6 +61,12 @@ class ViewController: UIViewController { delay(7) { //self.tvm[0].fire() + + for i in 0...200 { + let secIndex = Int(arc4random() % 200) + let section = self.tvm[secIndex] + NSLog("\(section.count)") + } return } /* diff --git a/Source/MYTableViewManager.swift b/Source/MYTableViewManager.swift index 7ce7d85..c914fbc 100644 --- a/Source/MYTableViewManager.swift +++ b/Source/MYTableViewManager.swift @@ -82,12 +82,12 @@ public class MYTableViewManager : NSObject { } } - private func syncSections() -> Bool { + private func syncSections(animation: MYAnimation) -> Bool { let length = insertedSectionsRange.1 - insertedSectionsRange.0 if length > 0 { let insertSet: NSIndexSet = NSIndexSet(indexesInRange: NSMakeRange(insertedSectionsRange.0, length)) insertedSectionsRange = (100, -1) - tableView?.insertSections(insertSet, withRowAnimation: .None) + tableView?.insertSections(insertSet, withRowAnimation: animation) return true } return false @@ -108,6 +108,7 @@ public extension MYTableViewManager { func fire(_ animation: MYAnimation = .None) -> Self { // TODO : implementation tableView?.reloadData() + insertedSectionsRange = (100, -1) return self } } @@ -115,23 +116,23 @@ public extension MYTableViewManager { // MARK - MYSectionDelegate extension MYTableViewManager : MYSectionDelegate { func reloadTableView() { - tableView?.reloadData() + fire(.None) } func reloadSections(indexSet: NSIndexSet, animation: MYAnimation) { - if !syncSections() { + if !syncSections(animation) { tableView?.reloadSections(indexSet, withRowAnimation: animation) } } func insertRows(indexPaths: [NSIndexPath], animation: MYAnimation) { - if !syncSections() { + if !syncSections(animation) { tableView?.insertRowsAtIndexPaths(indexPaths, withRowAnimation: animation) } } func deleteRows(indexPaths: [NSIndexPath], animation: MYAnimation) { - if !syncSections() { + if !syncSections(animation) { tableView?.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: animation) } }