2010-12-23 24 views
0

我知道這是一個非常常見的問題,我讀了大多數問題在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>> 
+0

旁註:你把它設置爲前應該叫`release`上``m_activity` nil` 。 – donkim 2010-12-23 20:11:15

回答

3

webViewDidFinishLoad功能可能不被稱爲列出了一個消息。如果Web視圖無法打開網址,可能會發生這種情況。無論如何,您還應該實施webView:didFailLoadWithError:方法並停止活動指示器。

CNC中

要接收來自一個UIWebView您需要設置控制器作爲一個UIWebView的委託事件。僅僅實現UIWebViewDelegate是不夠的。您可以通過更新viewDidLoad方法如下做到這一點:

-(void)viewDidLoad{ 
[super viewDidLoad]; 

webView.delegate = self; 
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://equinox.library.pitt.edu/limesurvey/index.php?sid=87435&lang=en"]]]; 
} 
+0

@ murat ...我添加了方法webView:didFailLoadWithError method..still指標仍然掛在 – 2010-12-23 19:23:32

+0

你有沒有設置控制器作爲UIWebView的代表? – murat 2010-12-23 19:51:25

0

您應該添加NSLog(@"in webViewDidFinishLoad")行代碼,並看控制檯,看看代碼傷害到那些點。由於這是一個非常簡單的例子,可能m_activity沒有連接到實際的對象?嘗試當您添加到您的viewDidLoad中結束,看看如果你得到一個地址或空:

NSLog(@"m_activity = %@",m_activity);