18

我从使用 iOS 7 SDK 在 XCode 5 下编程开始。当我使用“attributedText”创建时UITableViewControllerUIRefreshControl我将文本覆盖在图形之上UIRefreshControl(圆形进度动画)。

但是当我下拉并松开手指时,文本会跳到正常位置。为什么会这样?

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

    self.refreshControl = refreshControl;

在拉到底之前:

在拉到底之前

发布后UIRefreshControl

UIRefreshControl 发布后

4

3 回答 3

27

请试试这个。

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

}
于 2013-12-27T08:54:21.607 回答
0

layoutIfNeeded设置标题后调用

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];
于 2016-07-08T12:05:48.137 回答
-3

将您的代码更改为以下

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;

那应该可以解决您的问题

于 2013-10-18T14:13:29.710 回答