加载数据时显示 ActivityIndi​​cator

发布于 2024-09-19 15:19:07 字数 385 浏览 3 评论 0原文

我有一个 TabBarApplication,在一个视图中我从 URL 加载 XML 数据。

当我单击显示 UITableView 视图和从 XML 接收的数据的选项卡时,我想显示一个活动指示器。

  1. 这里推荐什么?我应该仅仅推送一个视图来显示活动指示器吗?今天,我在 viewDidLoad 中运行 XML 解析代码。也许如果我在 viewWillAppear 中运行该代码?

  2. 另一个问题是,每次用户切换回包含 UITableView 和 XML 数据的选项卡时,我是否应该重新加载 XML 数据。或者我应该以某种我不知道的方式检查它是否已经“获取”?

谢谢你!

I have a TabBarApplication and in one view I load XML-data from an URL.

When I click the tab which shows the view with the UITableView and the data received from the XML I would like to show a Activity indicator.

  1. What is recommended here? Should I push a view just for showing the activity indicator. Today I run the XML-parsing code in the viewDidLoad. Perhaps if I run that code in viewWillAppear instead?

  2. Another question is if I should reload the XML-data each time the user switches back to the tab containing the UITableView with the XML-data. Or should I in some way which I don't know of check if it's already "fetched"?

Thank you!

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

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

发布评论

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

评论(2

寄与心 2024-09-26 15:19:07

我的解决方案是在 viewDidLoad 中添加以下内容:

 loadingIndicator = [[UIActivityIndicatorView alloc] init];
 loadingIndicator.frame = CGRectMake(140, 190, 37, 37);
 loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
 [self.view addSubview:loadingIndicator];

 [self performSelectorInBackground:@selector(loadIndicator) withObject:loadingIndicator];
 [self performSelectorInBackground:@selector(getXmlData) withObject:nil];

My solution was that in the viewDidLoad add this:

 loadingIndicator = [[UIActivityIndicatorView alloc] init];
 loadingIndicator.frame = CGRectMake(140, 190, 37, 37);
 loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
 [self.view addSubview:loadingIndicator];

 [self performSelectorInBackground:@selector(loadIndicator) withObject:loadingIndicator];
 [self performSelectorInBackground:@selector(getXmlData) withObject:nil];
︶ ̄淡然 2024-09-26 15:19:07

这是我当前的代码。

[self getEvents] 执行 XML 操作,大约需要 2 秒。

loadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:loadingIndicator];
[loadingIndicator startAnimating];

 [self getEvents];

[loadingIndicator stopAnimating];

This is my current code.

[self getEvents] does the XML-fething and takes like 2 seconds.

loadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:loadingIndicator];
[loadingIndicator startAnimating];

 [self getEvents];

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