Search code examples
iostableviewmodalviewcontrollerios13uirefreshcontrol

pull to refresh in tableview from presenting modal in iOS 13 not working


I've used UIRefreshControl inside the tableview and it presented the view controller as automatically in ios 13. The tableview inside the same view controller is used.

vc.modalPresentationStyle = .automatic

The problem is that as soon as swipe refresh top the view controller it dismiss. i have prevented the following code for dismiss but the view controller still does not refresh from top.

vc.isModalInPresentation = true

How do I refresh the tableview without dismiss the view controller?


Solution

  • If iOS version is 10 later,use tableView's RefreshControl, don't ues addSubview.

    let refreshControl:UIRefreshControl = UIRefreshControl.init()
    
    if #available(iOS 10.0, *) {
       tableView.refreshControl = refreshControl
    } else {
       tableView.addSubview(refreshControl)
    }
    

    No matter isModalInPresentation is true or false.