OGeek|极客世界-中国程序员成长平台

标题: ios - 完全禁用 UIRefreshControl - iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:07
标题: ios - 完全禁用 UIRefreshControl - iOS

我有一个可使用 UIRefreshControl 刷新的 tableview。它工作正常。

要注意的是,当我单击 Edit 按钮(这是一个 UIBarButton)时,我希望禁用 UIRefreshControl。我在尝试完全禁用 UIRefreshControl 时遇到了极大的困难。我已经达到了我的表格内容肯定没有被刷新的地步(这很好),但用户仍然能够下拉并显示 spinny-symbol,然后短暂显示。有什么办法可以隐藏这个spinny-symbol?

我尝试了很多东西:refreshControl.endRefreshing()refreshControl.isHidden = truerefreshControl.removeFromSuperview()refreshControl = nil...

这是我的一些代码。 (isInEditMode 是一个实例变量,当点击 Edit 时为 true,点击 Done 时为 false。我相信这个 bool 值设置正确,所以我不认为这是问题所在。)

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. 
    }



}

编辑:我尝试了 How do I "hide" a UIRefreshControl? 中列出的所有解决方案,他们都没有解决我的问题。可能是因为那个帖子很老了——2013年。 (或者因为我使用 UIRefreshControl 的方式有所不同。该帖子中提出的主要解决方案是将 UIRefreshControl 设置为 nil endRefreshing() 之后。这对我不起作用。我还尝试了建议将 UIRefreshControl 的色调设置为 clear 的 hacky 解决方案. 而且,如上所述,我还尝试了 isHiddenremoveFromSuperview()。我的帖子与其他帖子不同的另一个因素是所有这些答案都是针对 Objective-C 的,而我对 Swift 3 很感兴趣。(尽管我很确定我能够将该线程上的建议翻译成 Swift。不过这无关紧要,因为它们都不适合我。)



Best Answer-推荐答案


从评论中的对话看来,答案似乎是在 viewDidAppear 中的 UITableView 中添加了多个 UIRefreshControl

View Controller 上的刷新控件属性是指最新添加的属性,并且该属性可能已被正确禁用。但是,任何先前添加的刷新控件仍将由 TableView 保留,即使 View Controller 不再引用它们。

修复方法是在 viewDidLoad 期间仅添加一次刷新控件并禁用它,但在切换到编辑模式时将其保留在表格 View 中,以便在离开编辑模式时重新启用它.

关于ios - 完全禁用 UIRefreshControl - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42545612/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4