Wednesday, June 12, 2013

How to Add a Reload or Refresh to the top of your view in iOS 6 with ARC

This has been around for a while but apple standardized it finally.

in the .h file of your tableview or collectionview or pretty much any view;

@interface myViewController : UICollectionViewController {
    //all your other declarations
    UIRefreshControl *refreshControl;
}

In your .m file, wherever you initialize the view;
if (self) {
    //other special setup items once you know your view exists
    refreshControl = [[UIRefreshControl alloc] initWithFrame:CGRectMake(0, -44, 320, 44)];
    [refreshControl addTarget:self action:@selector(reload:) forControlEvents:UIControlEventValueChanged];
    [self.collectionView addSubview:refreshControl];
}

- (void) reload:(id) sender {
    //all your reload commands go here like [tableview reloaddata];
}


No comments:

Post a Comment