Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mathieu De Haeck
5,645 PointsPhoto bombers - UIRefreshControl, end refreshing
I want to create a pull to refresh for refreshing my collectionView. but when i pull the spinner keeps on going...
in my test method i tried to end refreshing my refresh control, but i get an error that he doesn't know the property 'refreshControl'
In viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
// Pull to refresh
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor colorWithRed:242.0 / 255.0 green:122.0 / 255.0 blue:87.0 / 255.0 alpha:1.0];
[refreshControl addTarget:self action:@selector(test) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
self.collectionView.alwaysBounceVertical = YES;
}
in my test method:
- (void)test {
NSLog(@"refresh now !!!");
[self.refreshControl endRefreshing]; // error
}
1 Answer
Enara L. Otaegi
13,107 PointsYou can't call self.refreshControl if you don't have a property refreshControl. You are creating this refreshControl object in the viewDidLoad method so you can only manage this object in that method unless you pass it through as a parameter. You need to create it as a property to call self.refreshControl.