ios - 完全禁用 UIRefreshControl - iOS
<p><p>我有一个可使用 <code>UIRefreshControl</code> 刷新的 tableview。它工作正常。</p>
<p>要注意的是,当我单击 <code>Edit</code> 按钮(这是一个 <code>UIBarButton</code>)时,我希望禁用 <code>UIRefreshControl</code>。我在尝试完全禁用 <code>UIRefreshControl</code> 时遇到了极大的困难。我已经达到了我的表格内容肯定没有被刷新的地步(这很好),但用户仍然能够下拉并显示 spinny-symbol,然后短暂显示。有什么办法可以隐藏这个spinny-symbol?</p>
<p>我尝试了很多东西:<code>refreshControl.endRefreshing()</code>、<code>refreshControl.isHidden = true</code>、<code>refreshControl.removeFromSuperview()</code>、 <code>refreshControl = nil</code>...</p>
<p>这是我的一些代码。 (<code>isInEditMode</code> 是一个实例变量,当点击 <code>Edit</code> 时为 true,点击 <code>Done</code> 时为 false。我相信这个 bool 值设置正确,所以我不认为这是问题所在。)</p>
<pre><code>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.
}
}
</code></pre>
<p>编辑:我尝试了 <a href="https://stackoverflow.com/questions/19480424/how-do-i-hide-a-uirefreshcontrol" rel="noreferrer noopener nofollow">How do I "hide" a UIRefreshControl?</a> 中列出的所有解决方案,他们都没有解决我的问题。可能是因为那个帖子很老了——2013年。 (或者因为我使用 <code>UIRefreshControl</code> 的方式有所不同。该帖子中提出的主要解决方案是将 <code>UIRefreshControl</code> 设置为 <code>nil</code> <code>endRefreshing()</code> 之后。这对我不起作用。我还尝试了建议将 <code>UIRefreshControl</code> 的色调设置为 <code>clear</code> 的 hacky 解决方案. 而且,如上所述,我还尝试了 <code>isHidden</code> 和 <code>removeFromSuperview()</code>。我的帖子与其他帖子不同的另一个因素是所有这些答案都是针对 Objective-C 的,而我对 Swift 3 很感兴趣。(尽管我很确定我能够将该线程上的建议翻译成 Swift。不过这无关紧要,因为它们都不适合我。)</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>从评论中的对话看来,答案似乎是在 <code>viewDidAppear</code> 中的 <code>UITableView</code> 中添加了多个 <code>UIRefreshControl</code>。 </p>
<p> ViewController 上的刷新控件属性是指最新添加的属性,并且该属性可能已被正确禁用。但是,任何先前添加的刷新控件仍将由 TableView 保留,即使 ViewController 不再引用它们。 </p>
<p>修复方法是在 <code>viewDidLoad</code> 期间仅添加一次刷新控件并禁用它,但在切换到编辑模式时将其保留在表格 View 中,以便在离开编辑模式时重新启用它. </p></p>
<p style="font-size: 20px;">关于ios - 完全禁用 UIRefreshControl - iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42545612/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42545612/
</a>
</p>
页:
[1]