加载数据时显示活动指示器

时间:2010-09-15 11:11:55

标签: android-activity indicator

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

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

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

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

  3. 谢谢!

2 个答案:

答案 0 :(得分:1)

我的解决方案是在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];

答案 1 :(得分:0)

这是我目前的代码。

[self getEvents]执行XML-fething并花费2秒钟。

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

 [self getEvents];

[loadingIndicator stopAnimating];
相关问题