2017-03-18 11 views
1

UITableViewControllerでプルダウンをリフレッシュするように実装しました。ユーザーがホーム画面に移動してアプリに戻ると、UIRefreshControlが停止しているように見えますが、これはまだ表示されていますが回転していない場合に実行されます。だからSOのいくつかのソリューションを試してみましたが、何も機能していません。UIRefreshControlがフォアグラウンドiOS 10に戻ります。

当社の実装:

Restarting the refreshing when entering foreground when currently refreshingを::

if refreshControl!.isRefreshing == true { 
    refreshControl!.endRefreshing() 
    refreshControl!.beginRefreshing() 
    self.tableView.setContentOffset(CGPoint(x: 0, y: - refreshControl!.frame.size.height - self.topLayoutGuide.length), animated: true) 
} 

...我々が想定していない場合は、次の解決策は、リフレッシュを終了についてです私たちが試した

//Configure pull to refresh when user "pulls down" 
    self.refreshControl?.addTarget(self, action: #selector(NotificationTableViewController.handleRefresh(refreshControl:)), for: UIControlEvents.valueChanged) 

    //In handleRefresh we will explicitly start the refresh control if this is a background refresh and not a user initiated pull to refresh 
    refreshControl.beginRefreshing() 
    self.tableView.setContentOffset(CGPoint(x: 0, y: -refreshControl.frame.size.height - self.topLayoutGuide.length), animated: true) 

    //Then once we have reloaded data we stop the refresh in the same manner for user initiated or background refresh (done on main thread) 
    refreshControl.endRefreshing() 

ソリューションさわやかになる。私は

Calling endRefreshing() when entering foreground if not refreshing ...それらを試してみましたが、我々の場合には、私たちはさわやかなことになっている:

if refreshControl?.isRefreshing == false { 
    refreshControl?.endRefreshing() 
} 

Sending the refresh control to the back on entering foreground

self.refreshControl?.superview?.sendSubview(toBack: self.refreshControl!) 

誰もがiOS版10上で動作の修正を持っていますか?

+0

あなたはUIRefreshControlための実装を喜ばせることができますか? – hasan83

+0

実装の詳細を追加 –

+1

これをチェックしましたか? http://stackoverflow.com/questions/24341192/uirefreshcontrol-stuck-after-switching-tabs-in-uitabbarcontroller – hasan83

答えて

1

一般的に動作したのはto stop the refresh control on background/disappear and start it again on foreground/appearでした。

でも、これには競合条件の問題があります。私たちは、スレッド#1がバックグラウンドでデータをロードし、別のスレッド#2がフォアグラウンド/出現処理を処理しています。スレッド#1がデータロード完了のためにリフレッシュインジケータを停止していると同時にスレッド#2が状態をチェックしてリフレッシュ制御を開始しようとすると、リフレッシュ制御が回転しているがロードデータ要求すでに完了。我々はこれをすべて同期化しようとする可能性がありますが、努力する価値はありません。

バックグラウンドでのリフレッシュコントロールを停止/消滅することに決めました。負荷がかけられている間にユーザーが画面に戻ると、ユーザーにリフレッシュ制御を表示しようとすることはありません。 refreshControl!.isRefreshingもし

if refreshControl!.isRefreshing == true { 
     refreshControl!.endRefreshing() 
    } 
0

falseですが、あなたはまだそのグリッチは、これを使用する必要があり:

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 

    //fixes bug with refreshControl freezing while switching tabs 

    if tableView.contentOffset.y < 0 { 
    tableView.contentOffset = .zero 
    } 
} 
関連する問題