19

I start with programming under XCode 5 with iOS 7 SDK. And when I create UITableViewController with UIRefreshControl with 'attributedText' I've got text overlayed on top of UIRefreshControl graphics (circle progress animation).

But when I pull down and release my finger, text jumps to its normal position. Why it happened?

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];

    self.refreshControl = refreshControl;

Before pulling down to the end:

Before pulling down to the end

After UIRefreshControl release:

After UIRefreshControl release

Unheilig
  • 16,196
  • 193
  • 68
  • 98
woozly
  • 1,363
  • 1
  • 14
  • 24
  • 3
    See my answer here: http://stackoverflow.com/questions/19121276/uirefreshcontrol-incorrect-title-offset-during-first-run-and-sometimes-title-mis – Ben Jackson Oct 01 '13 at 21:25

3 Answers3

27

Please try this.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.refreshControl beginRefreshing];
        [self.refreshControl endRefreshing];
    });

}
jeilsoft
  • 572
  • 5
  • 13
  • Additionally, if you've added the refresh control through interface builder, just exposed your existing control in your class and then use the dispatch_async as in this answer. That'll let you set your variables in IB and results in less code. – Sandy Chapman May 22 '14 at 17:05
  • Works. Assuming there is a bug in apples code as I cannot imagine they intended this solution. – lostintranslation May 07 '15 at 02:26
  • Apple did not fix this problem, yet ! Thank you for your little "hack" ;) – androniennn Oct 20 '15 at 12:47
0

Call layoutIfNeeded after setting title

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];
[self.refreshControl layoutIfNeeded];
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
-3

Change your code to following

self.refreshControl = [UIRefreshControl new];
[self.refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];

self.refreshControl = refreshControl;

That should fix your problem

CTiPKA
  • 2,944
  • 1
  • 24
  • 27