Skip to content

Commit

Permalink
reset insertedSectionRange after reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
nghialv committed Feb 16, 2015
1 parent 552b366 commit abf2d25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Example/MYTableViewManager/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
/*
Expand Down
13 changes: 7 additions & 6 deletions Source/MYTableViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -108,30 +108,31 @@ public extension MYTableViewManager {
func fire(_ animation: MYAnimation = .None) -> Self {
// TODO : implementation
tableView?.reloadData()
insertedSectionsRange = (100, -1)
return self
}
}

// 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)
}
}
Expand Down

0 comments on commit abf2d25

Please sign in to comment.