skip to Main Content

Without prefersLargeTitles, I should have to pull down a bit before the UIRefreshControl begins the refresh, but when I turn on large titles, it starts instantly.

I have removed the Storyboard and I am trying to create everything programatically.
What am I missing?

import Foundation
import UIKit

class TweakManagerViewController: UIViewController {
    var tableView = UITableView()
    var refreshControl = UIRefreshControl()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupTableView()
        
        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.title = "Title"
        
    }
    
    func setupTableView() {
        tableView.refreshControl = refreshControl
        view.addSubview(tableView)
        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        tableView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        tableView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    }
}

2

Answers


  1. Chosen as BEST ANSWER

    I was finally able to solve it. I was supposed to use a UITableViewController, not a UIViewController. After switching to a UITableViewController, everything works as expected.


  2. You have added everything correctly make sure that you have also added the target action to make the UIRefreshControl work as expected

    // Add target-action for refresh control in your view did load
        refreshControl.addTarget(self, action: #selector(refreshData), for: .valueChanged)
    
    @objc func refreshData() {
            // Perform the actions you want when the user triggers the refresh control
            refreshControl.endRefreshing()
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search