Skip to content

Instantly share code, notes, and snippets.

@auramagi
Created January 12, 2022 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auramagi/a5af70718b0e31af37403cd607b489d9 to your computer and use it in GitHub Desktop.
Save auramagi/a5af70718b0e31af37403cd607b489d9 to your computer and use it in GitHub Desktop.
UIRefreshControl stuck when changing tabs in UITabBarController
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func makeRefreshControl() -> UIRefreshControl {
let refresh = UIRefreshControl()
let action = UIAction { [weak refresh] _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
refresh?.endRefreshing()
}
}
refresh.addAction(action, for: .valueChanged)
return refresh
}
let tc = UITabBarController()
tc.viewControllers = [
{
let vc = UITableViewController(style: .plain)
vc.tableView.dataSource = self
vc.refreshControl = makeRefreshControl()
vc.title = "One"
vc.tabBarItem.image = .init(systemName: "1.circle")
return vc
}(),
{
let vc = UIViewController()
vc.title = "Two"
vc.tabBarItem.image = .init(systemName: "2.circle")
return vc
}()
]
window?.rootViewController = tc
tc.view.backgroundColor = .systemBackground
return true
}
}
extension AppDelegate: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
cell.textLabel?.text = "Cell \(indexPath.row)"
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment