SpringIndicator icon indicating copy to clipboard operation
SpringIndicator copied to clipboard

Preventing second refresh

Open tosbaha opened this issue 10 years ago • 2 comments

I am trying to prevent second refresh before finishing the first one.

    override func viewDidLoad() {
        super.viewDidLoad()
        refreshController.indicator.lineColor = UIColor.selectedOrange()
        refreshController.addTarget(self, action: "onRefresh", forControlEvents: .ValueChanged)
        tableView.addSubview(refreshController)
}

    func onRefresh() {
        if refreshController.refreshing {
            print("Returning")
            return
        } 
 // do the refresh
}

tosbaha avatar Sep 19 '15 11:09 tosbaha

Hi, @tosbaha

refreshing was something issue?

KyoheiG3 avatar Sep 20 '15 04:09 KyoheiG3

My problem is I can't stop second refreshing from onRefresh For example

    func onRefresh() {
        print("Refreshing \(refreshController.refreshing)")
        if refreshController.refreshing {
           return
        }
        let delay = 1.0 * Double(NSEC_PER_SEC)
        let time  = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
        dispatch_after(time, dispatch_get_main_queue()) {
            self.refreshList(){ error in //some lengthy task
                self.refreshController.endRefreshing()
            }
        }
    }

I don't know why but it does just keep spinning. I was expecting to see 1 refresh which will call my refreshList method then when it does it will call self.refreshController.endRefreshing() However if I change the condition to

   if !refreshController.refreshing {
           return
        }

It works. I really didn't get it.

tosbaha avatar Sep 20 '15 08:09 tosbaha