0
我的活動指標存在問題。我有一個按鈕,可以在活動指示器之間重新加載網站和顯示器。問題在於,如果用戶在按鈕上點擊超過1次,它將重建一個新指標,並且該指標始終在屏幕上凍結。 按鈕禁用不起作用。有沒有人解決這個問題。請幫忙。iOS刪除所有活動指標
這裏是我的代碼:
-(IBAction) buttonReload {
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)){
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:@"No Inet!" message:@"You need a Inet Connection..."
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
else
{
//Website loading
[self performSelector: @selector(doLoadWebsite)
withObject: nil
afterDelay: 0];
return;
}
}
- (void) doLoadWebsite
{
//add activity indicator
NewsActivity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(140.0f, 180.0f, 40.0f, 40.0f)];
[NewsActivity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview: NewsActivity];
[NewsActivity startAnimating];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(finishActivity) userInfo:nil repeats:YES];
//NewsActivity.backgroundColor = [UIColor grayColor];
NewsActivity.hidesWhenStopped = YES;
// Show Status Bar network indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//perform time-consuming tasks
//load News Website
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
}
-(void) finishActivity {
if (!webView.loading) {
[self.NewsActivity removeFromSuperview];
[NewsActivity stopAnimating];
//Hide network activity indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
else {
[NewsActivity startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
}
你能給一點樣品嗎?如果我用[NewsActivity removeFromSuperview]嘗試它;指示器將永遠不會顯示。 – CaspervanDoorn
是的,再次將它添加到子視圖:) – Legolas
它不起作用。其他指標將一次又一次地顯示在循環中...... – CaspervanDoorn