I got a UIRefreshControl to work with a UIScrollView :
- (void)viewDidLoad { UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; scrollView.userInteractionEnabled = TRUE; scrollView.scrollEnabled = TRUE; scrollView.backgroundColor = [UIColor whiteColor]; scrollView.contentSize = CGSizeMake(500, 1000); UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(testRefresh:) forControlEvents:UIControlEventValueChanged]; [scrollView addSubview:refreshControl]; [self.view addSubview:scrollView]; } - (void)testRefresh:(UIRefreshControl *)refreshControl { refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSThread sleepForTimeInterval:3];
You must update the data in a separate stream or block the main stream (which the user interface uses to update the user interface). Therefore, when the main thread is busy updating data, the user interface is also blocked or frozen, and you will never see a smooth animation or counter.
EDIT: ok, I am doing the same thing as OP, and now I have added some text to it (ie "Pull to Refresh"), and it needs to go back to the main stream to update this text.
Updated answer.
Padin215 Feb 21 '13 at 17:08 2013-02-21 17:08
source share