0

我有一个加载屏幕,它有一个动画活动指示器和显示“正在加载”的标签。全部使用 Interface Building 创建。在我的 RSS 提要完成解析之前,此屏幕会显示给用户。

如果设备没有互联网连接,则从视图中删除活动指示器,在其位置显示一个重新加载按钮,并且标签文本更改为“重新加载”

@synthesize loadingView, loadingIndicator, loadingLabel;

BOOL isFirstOffersLoad = YES;

-(void)viewDidAppear:(BOOL)animated
{
    if (isFirstOffersLoad) [self parseFeed];
    [super viewDidAppear:animated];

}

-(void)viewDidLoad
{
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Navigation"]];
}

- (void)parseFeed
{
[self.loadingIndicator startAnimating];
self.loadingIndicator.hidesWhenStopped = YES;

NetworkStatus networkStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
if (networkStatus == NotReachable) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Unavailable" message:@"More Cobalt requires an Internet connection" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];

    self.loadingLabel.text = @"Reload";
    self.loadingIndicator.hidesWhenStopped = YES;
    [self.loadingIndicator stopAnimating];
    self.reloadButton.hidden = NO;
}
else {
    // Download and parse XML data
    [loadingView removeFromSuperview];
    [self.loadingIndicator stopAnimating];
    isFirstOffersLoad = NO;
}
}

- (IBAction)reload:(id)sender {
    [self parseFeed];
}

但是,当您点击重新加载按钮时,我希望按钮隐藏,活动指示器重新出现,并且标签的文本再次更改为“正在加载”。就像您第一次启动应用程序时一样。

有人可以帮我吗?

4

1 回答 1

0

由于您的 reload 方法会响应按钮按下,因此只需添加所需的更改:

- (IBAction)reload:(id)sender {
    [self parseFeed];

    self.loadingLabel.text = @"Loading";
    [self.loadingIndicator startAnimating];
    self.reloadButton.hidden = YES;
} 
于 2013-11-05T19:03:05.740 回答