绘制后重绘 UITableViewCell

发布于 2024-12-03 04:32:10 字数 751 浏览 5 评论 0原文

我正在向 UITableView 添加“拉动加载更多”。我已经重新加载工作,并且可以添加更多数据,但我试图在数据加载时显示 UIActivityIndi​​catorView 。我已经设法让当前配件消失,但无法让活动指示器自行绘制。

这是我在 UITableViewCell 子类中的代码:

-(void) toggleLoading:(bool)showLoading {
    if(showLoading) {
        [self.accessoryView setHidden:true];
        isLoading = false;
    } else {
        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        spinner.frame = CGRectMake(0, 0, 24, 24);
        self.accessoryView = spinner;
        [spinner startAnimating];
        [spinner release];
        isLoading = true;
        [self.backgroundView setNeedsDisplay];
    }
}

调用该方法,当数据加载完成时,再次显示正确的附件。我需要额外的步骤吗?

I'm adding 'pull to load more' to a UITableView. I've got the reloading working and I can add more data, but I'm trying to display a UIActivityIndicatorView when the data loads. I've managed to get the current accessory to disappear, but I can't make the actitity indicator draw itself.

This is the code I have in my UITableViewCell subclass:

-(void) toggleLoading:(bool)showLoading {
    if(showLoading) {
        [self.accessoryView setHidden:true];
        isLoading = false;
    } else {
        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        spinner.frame = CGRectMake(0, 0, 24, 24);
        self.accessoryView = spinner;
        [spinner startAnimating];
        [spinner release];
        isLoading = true;
        [self.backgroundView setNeedsDisplay];
    }
}

The method is called and when the data finishes loading, the correct accessory is shown again. Is there an extra step I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙幽之幻 2024-12-10 04:32:10

您不应该在 didSelectRowAtIndexPath 中绘制微调器吗?

顺便说一句我会用:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

Shouldn't you be drawing the spinner in didSelectRowAtIndexPath?

btw I would use:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
甜心小果奶 2024-12-10 04:32:10

结果我试图从一个单独的线程(使用 GCD)调用它,因此更新 UI 时出现滞后。解决方案是将 UI 调用移至 UI 线程上。

Turned out I was trying to call this from a separate thread (using GCD), hence the lag in updating the UI. The solution was to move the UI calls onto the UI thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文