无法隐藏按钮然后取消隐藏它

时间:2013-11-05 18:34:28

标签: ios objective-c uibutton uiactivityindicatorview

我有一个加载屏幕,其中有一个动画活动指示器和标签,显示“正在加载”。全部使用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];
}

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

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

由于您的重新加载方法响应按下按钮,只需添加所需的更改:

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

    self.loadingLabel.text = @"Loading";
    [self.loadingIndicator startAnimating];
    self.reloadButton.hidden = YES;
}