Using UIRefreshControl in UIScrollView

How to add refresh control to a scroll view

First, set your uiviewcontroller self.view background to black.

Then create a scroll view container and set it to red.

Then have the scroll view container add a refresh control.

Finally, draw an orange square and have the container add that.

self.view
—container
——-refresh control (operates on container as background)
——-square (other UIViews added to container will be pulled down)

Once you run the app and pull down, you’ll see that the refresh control is added onto the scroll view and operates using the scrollview as the background.

refresh_control_added

Code

NSInternalInconsistencyException

If you happen to try to add the refresh control to a uiviewcontroller’s self.view, you’ll get a compiler error:

NSInternalInconsistencyException’, reason: ‘UIRefreshControl may only be managed by a UITableViewController’

You can only add it to a UITable, UICollection, and UIScrollView.

Making a successful View transition when UIRefresh is pulled

If you want to transition your view beautifully when the user pulls down on the refresh control, set your controls up so that there are 2 containers.

container1 – refresh control, other views
container2 – refresh control, other views

Then when a refresh control is pulled, you hit the event method of the ‘pull’ and make sure you animate the containers to switch. Something like this:

Leave a Reply