문제

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

도움이 되었습니까?

해결책

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];
    });

}

다른 팁

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];

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top