UIRefreshControl的文本覆盖在刷新指示器上

19

我是从XCode 5和iOS 7 SDK开始编程的。当我使用带有'attributedText'的UIRefreshControl创建UITableViewController时,文本重叠在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释放后:

在释放<code>UIRefreshControl</code>后


3
请看我在这里的答案:https://dev59.com/S2Ik5IYBdhLWcg3wl_TE - Ben Jackson
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];
    });

}

此外,如果您已经通过界面构建器添加了刷新控件,只需在类中公开现有控件,然后像这个答案中一样使用dispatch_async。这将允许您在IB中设置变量,并减少代码量。 - Sandy Chapman
正常工作。假设苹果的代码存在错误,因为我无法想象他们打算使用这种解决方案。 - lostintranslation
苹果还没有解决这个问题!感谢您的小“黑科技” ;) - androniennn

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

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

这应该可以解决你的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接