我知道這是一個非常常見的問題,我讀了大多數問題在stackoverflow中,但仍然無法弄清楚如何從視圖中刪除uiactivityindicatorview。 請找代碼iphone - uiactivityindicatorview並不隱藏
@implementation FeedBackViewController
@synthesize m_activity,webView;
-(void)viewDidLoad{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://equinox.library.pitt.edu/limesurvey/index.php?sid=87435&lang=en"]]];
}
- (void)dealloc {
[m_activity release];
[webView release];
[super dealloc];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[m_activity stopAnimating];
[m_activity removeFromSuperview];
m_activity = nil;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"in webViewDidFinishLoad")
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
m_activity.center = self.view.center;
[self.view addSubview: m_activity];
[m_activity startAnimating];
}
頭文件
@interface FeedBackViewController : UIViewController<UIWebViewDelegate>{
IBOutlet UIWebView *webView;
IBOutlet UIActivityIndicatorView *m_activity;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) UIActivityIndicatorView *m_activity;
而且下面,我檢查了,說,隱藏停止時,IB的框。我把NSLog(@"in webViewDidFinishLoad")
放在webViewFinishLoad方法中,似乎因爲某些原因不會觸及該方法。 和
NSLog(@"m_activity = %@",m_activity);
在viewDidLoad方法
,它在控制檯
> m_activity = <UIActivityIndicatorView:
> 0x4d3d920; frame = (150 79; 20 20);
> hidden = YES; opaque = NO; autoresize
> = RM+BM; layer = <CALayer: 0x4d35ce0>>
旁註:你把它設置爲前應該叫`release`上``m_activity` nil` 。 – donkim 2010-12-23 20:11:15