0

I have added pull to refresh in UITableview with two custom prototype cells ,I have tryied with these two type of code one through adding UIRefreshcontrol as a subview of tableview and other through UITableViewController

1)UIRefreshcontrol as a subview of tableview

self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[listTable addSubview:self.refreshControl];

2)Through UITableViewController

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = listTable;

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshContacts) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;

But neither both of them seems to work.

iamVishal16
  • 1,780
  • 18
  • 40
Super Xtreem
  • 187
  • 1
  • 10

4 Answers4

0

Check these links for information

UIRefreshControl - Pull To Refresh in iOS 7

http://www.techrepublic.com/blog/software-engineer/better-code-implement-pull-to-refresh-in-your-ios-apps/

Example

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.backgroundColor = [UIColor clearColor];
refreshControl.tintColor = [UIColor whiteColor];
[refreshControl addTarget:self
                   action:@selector(getLatestData)
         forControlEvents:UIControlEventValueChanged];

[yourTableviewName addSubview:refreshControl];


   -(void)getLatestData
{
 // here add your reload method
  [self XXXXX]; 

  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"MMM d, h:mm a"];
   NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
   NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                                    forKey:NSForegroundColorAttributeName];
   NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
        refreshControl.attributedTitle = attributedTitle;

        [refreshControl endRefreshing];
    }
Community
  • 1
  • 1
DHEERAJ
  • 1,478
  • 12
  • 32
0

The second way is nearly identical to the code I suggested in What's the Best Way to Get a "Pull to Refresh" from a UITableView? , so I'm thinking that your bug is in the tableViewController. Is it getting retained?

Community
  • 1
  • 1
Tim Kokesh
  • 879
  • 7
  • 10
  • Does tableview constraints issue affects the refreshcontrol ?? – Super Xtreem Jul 04 '15 at 10:32
  • I'm not sure, but I think the problem with your code is that your UITableViewController isn't being retained (that I can see); none of your other variables are referencing it. If your UITableViewController is getting released by ARC, `tableViewController.refreshControl = self.refreshControl;` won't do anything. My guess is that if you add tableViewController as a strong property to your object, this code should work. – Tim Kokesh Jul 04 '15 at 10:36
0

In .h

@property(nonatomic,strong) UIRefreshControl *refreshControl;

In .m

- (void)viewDidLoad {
    [super viewDidLoad];
 //Initialize the refresh control
    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(refreshBrandList:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:self.refreshControl];

}


-(void) refreshBrandList:(id)sender{
    [self ServiceCall];
    [self.refreshControl endRefreshing];


}
Nischal Hada
  • 3,230
  • 3
  • 27
  • 57
0

SVPullToRefresh + SVInfiniteScrolling

  • Easy to use.
  • Provide Pull up and down to refresh

Easy to add pull-to-refresh and infinite scrolling fonctionalities to any UIScrollView or UITableView

iamVishal16
  • 1,780
  • 18
  • 40
  • Using this can we update the frame of the refresh icon bit lower ? ,I find the refresh icon on the extreme top So, that it is not fully visible – Super Xtreem Jul 04 '15 at 11:11
  • Yes, You can. You need to edit UIActivityIndicatorView style with a white large in SvPullToRefreshView Class and put appropriate tint color if needed. – iamVishal16 Jul 04 '15 at 13:27