Showing posts with label UIRefreshControl. Show all posts
Showing posts with label UIRefreshControl. Show all posts

Thursday, September 29, 2016

Refresh Control on TableView

You can use the table view's new refreshControl property to set your UIRefreshControl.
 
override func viewDidLoad() {
    super.viewDidLoad()
    
    tableView.delegate = self
    tableView.dataSource = self
    
    refreshControl.addTarget(self, action: #selector(ViewController.refreshData), 
        for: UIControlEvents.valueChanged)
    
    if #available(iOS 10.0, *) {
        tableView.refreshControl = refreshControl
    } else {
        tableView.addSubview(refreshControl)
    }
}

func refreshData() {
    // Refresh data code
    
    tableView.reloadData()
    refreshControl.endRefreshing()
}
 


(Xcode 8, Swift 3.0)

Refresh Control on Collection View

You can use the new refreshControl property on the UICollectionView to assign your UIRefreshControl.
 

override func viewDidLoad() {
    super.viewDidLoad()
        
    collectionView.delegate = self
    collectionView.dataSource = self
        
    refreshControl.addTarget(self, action: #selector(CollectionVC.refreshData), 
        for: UIControlEvents.valueChanged)
    refreshControl.attributedTitle = NSAttributedString(string: "Refresh Collection View",
        attributes: nil)
        
    if #available(iOS 10.0, *) {
        collectionView.refreshControl = refreshControl
    } else {
        collectionView.addSubview(refreshControl)
    }
}
    
func refreshData() {
    // Your get data code
        
    collectionView.reloadData()
    refreshControl.endRefreshing()
}

 


(Xcode 8, Swift 3.0)

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...