简体   繁体   中英

Completely disabling UIRefreshControl - iOS

I have a tableview that is refreshable with a UIRefreshControl . It works fine.

The catch is that I wish to disable the UIRefreshControl when I click an Edit button (which is a UIBarButton ). I am having extreme difficulties in trying to disable UIRefreshControl completely. I've gotten it to the point where the content of my table is definitely not being refreshed (which is good), but the user is still able to pull down and reveal the spinny-symbol, which then displays briefly. Is there any way I can hide this spinny-symbol?

I've tried so many things: refreshControl.endRefreshing() , refreshControl.isHidden = true , refreshControl.removeFromSuperview() , refreshControl = nil ...

Here's some of my code. ( isInEditMode is an instance variable that is true when Edit is tapped and false when Done is tapped. I am confident that this boolean is set properly, so I don't believe that's the problem.)

func refreshTable(sender: UIRefreshControl) {

    if !isInEditMode {

        self.refreshControl.beginRefreshing()
        refreshProfile() 

    // this works exactly as I want it to

    }

    else {
        refreshControl.endRefreshing()
        // OR refreshControl.isHidden = true
        // OR refreshControl = nil
        // OR refreshControl.removeFromSuperview()

        // refreshProfile() not called, so table doesn't update, but the user can still pull down and the spinny icon shows. I do not want this. 
    }



}

EDIT: I tried all of the solutions set forth in How do I "hide" a UIRefreshControl? , and none of them solved my issue. It may be because that post is quite old--2013. (Or because something about the way I'm using UIRefreshControl is different. The primary solution set forth in that post is to set the UIRefreshControl to nil after endRefreshing() . This did not work for me. I also tried the hacky solution suggested of setting the tint of the UIRefreshControl to clear . And, as outline above, I also tried isHidden and removeFromSuperview() . Another factor distinguishing my post from that other post is that all of those answers for Objective-C, whereas I am interested in Swift 3. (Although I'm pretty sure I was able to translate the suggestions on that thread to Swift. That's beside the point though, since none of them worked for me.)

From the conversation in comments it seems like the answer is that multiple UIRefreshControl s are being added to the UITableView in viewDidAppear .

The refresh control property on the view controller refers to the latest one added, and that one likely is being disabled properly. However, any previously added refresh controls would still be retained by the table view, even though the view controller no longer has a reference to them.

The fix is to only add the refresh control once, during viewDidLoad and disable it, but leave it in the table view when switching to edit mode so it can be re-enabled when leaving edit mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM