UIRefreshControl in iOS6


All our clients want to have a basic functionality when its regarding the data display in the table view and that is having a spinner at it’s top. To do this you have the EGORefreshDemo that is available and is a little bit tricky to handle but is quite cool.

In iOS 6 apple has been a little open hearted to provide you with a class named UIRefreshControl which is similar in fashion, so in this post we will have a look at the UIRefreshControl and will use it with a table view.

Step 1: Open you Xcode 4.5 and create an empty view based project and add a UITableViewController file to it that will have a list of various products. After you have done this then add your table view controller view in the app delegate and the run your project to see if you have got things right.

Step 2: After completing step no1 select your tableviewcontroller.h file and declare a global object of UIRefreshControl.

Note: This class requires a call back method that will get triggered once you pull it so in simple terms we need a function, which we will assign to the UIRefreshControl and this function will be called when we pull our table to refresh it.


So now in your table view controller.h file you will be doing two things:

1. Creating a global object of the UIRefreshControl

2. Declaring a function that will be called when you pull the refresh control to refresh the table.
Step 3: Alright now after Step no 2 it’s time to switch to your tableviewcontroller.m file and select the view did load method where you will initialize the object of UIRefreshControl.



Code Explanation:I have used comments to make you understand the code.

After initializing the control it’s time to work on the callback method that would be associated with the UIRefreshControl.






Step 4: All set and done its time to run your project and see how it looks try pulling your table view and see apple’s new UIRefreshControl. Given below is the output for the same.














My Views on UIRefreshControl: After looking at this your client may or may not ask you to customize the UIRefreshControl class or stick with EGORefresh library, this class is available for iOS6 and not with any previous versions. But anyways its quite handly and less code is involved so it’s a good class by apple. 

You may download the source code of this project from here.

I hope that by reading this tutorial you have understood how to use the UIRefreshControl in iOS 6 and if there are any doubts popping in your mind the feel free to ask me by comments or by mail.

Happy iCoding and have a great day.

Comments

  1. Hi...
    I am not able to set self.refreshControl=refreshcontrollerObject;
    it is showing error, i have used uiviewcontroller and drag the table on viewcontroller.

    All code was working before setting UIRefreshController.

    Please help it out from this problem

    Thank you for your time

    ReplyDelete
  2. Hey @Shoeb have you downloaded the code and tried to run it, is it working at your end ?
    Radix has mentioned that you need Xcode 4.5 and not previous version.
    Also could you copy+paste the error you are getting so that we can come to know what may be the issue ?

    Happy Day

    ReplyDelete
  3. Use a tableviewcontroller, not a viewcontroller

    ReplyDelete

Post a Comment