Swift, Pull to refresh entire view, possible?

705 Views Asked by At

I've been researching how to add Pull to Refresh in Swift to my View. However, Everything I come across is about reloading the tableview. I dont have a tableview. The view I have checks for internet connection. If the internet connection does not exist I want them to be able to pull down to refresh and check the connection again. If it does exist - perform function. etc..

Is it even possible? Apologies - I am a noob :)

2

There are 2 best solutions below

0
On

You know, UITableView is also a UIView in the top of the hierarchy. I suggest you use UIScrollView and place you view inside that scrollview and listen for scroll events. And if the user pulls it down, you call your method and smoothly place the scrollview in its start offset with the setContentOffset method.

1
On

Hmm... You would have to implement it yourself. I suggest that instead of making your user do something, set up a callback for when internet is connected and have the code do it automatically. What internet connection library are you using? I use AFNetworking, but I'm sure Alamofire would work well too.

I strongly suggest you add AFNetworking to your project, it's easy to do with cocoapods. Then you just use the AFNetworkReachabilityManager class. Set it's ReachabilityStatusChangeBlock and then call startMonitoring. Your callback will be called whenever the network status changes.

(https://github.com/AFNetworking/AFNetworking)