绘制后重绘 UITableViewCell
我正在向 UITableView 添加“拉动加载更多”。我已经重新加载工作,并且可以添加更多数据,但我试图在数据加载时显示 UIActivityIndicatorView 。我已经设法让当前配件消失,但无法让活动指示器自行绘制。
这是我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该在 didSelectRowAtIndexPath 中绘制微调器吗?
顺便说一句我会用:
Shouldn't you be drawing the spinner in didSelectRowAtIndexPath?
btw I would use:
结果我试图从一个单独的线程(使用 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.