0

目前我正在iphone應用程序中使用UIWebView(在presentModelViewController中顯示的網頁)在屏幕上顯示網頁,然後我添加UIActivityIndi​​catorView以顯示加載網址請求,但UIActivityIndi​​catorView沒有顯示在屏幕上,我試了我的水平最好,請幫助我。iPhone中的UIActivityIndi​​catorView問題?

由於提前

我嘗試這樣做:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    activity.frame=CGRectMake(140, 240, 40, 40); 
    [self.view addSubview:activity]; 

    web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    web.delegate=self; 
    web.backgroundColor=[UIColor clearColor]; 
    NSURL *url = [NSURL URLWithString:@"http://wrwr.rww.com/erqrrq"]; 
    NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
    [web loadRequest:req]; 
    [self.view addSubview:web]; 
} 

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    [activity stopAnimating]; 
} 

- (void)webViewDidStartLoad:(UIWebView *)webView 
{  
    [activity startAnimating]; 
} 
+2

嘗試先添加Web視圖,然後再添加活動視圖,否則Web視圖可能會隱藏活動視圖。 –

+0

你可以嘗試添加你的活動indicatore在webview像: - [web addSubview:activity]; –

回答

0

試試這個,

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    web.delegate=self; 
    web.backgroundColor=[UIColor clearColor]; 
    NSURL *url = [NSURL URLWithString:@"http://wrwr.rww.com/erqrrq"]; 
    NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
    [web loadRequest:req]; 
    [self.view addSubview:web]; 

    activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    activity.frame=CGRectMake(140, 240, 40, 40); 
    [self.view addSubview:activity]; 
    [self.view bringSubviewToFront:activity]; 
} 
+0

請參閱編輯。你的代碼不工作,因爲你的活動指標被webview隱藏。在Web視圖上方放置活動指示器並將活動指示器放在前面即可解決此問題。希望這可以幫助你。 :) –

0

定義的UIWebView後定義UIActivityIndi​​catorView。

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 


     web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
     web.delegate=self; 
     web.backgroundColor=[UIColor clearColor]; 
     NSURL *url = [NSURL URLWithString:@"http://wrwr.rww.com/erqrrq"]; 
     NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
     [web loadRequest:req]; 
     [self.view addSubview:web]; 

    activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     activity.frame=CGRectMake(140, 240, 40, 40); 
     [self.view addSubview:activity]; 
    } 
1

增加自己的活動indicatore瀏覽到的網頁視圖這樣的: -

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
activity.frame=CGRectMake(140, 240, 40, 40); 


web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; 
web.delegate=self; 
web.backgroundColor=[UIColor clearColor]; 
NSURL *url = [NSURL URLWithString:@"http://wrwr.rww.com/erqrrq"]; 
NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
[web loadRequest:req]; 
[web addSubview:activity]; 
[self.view addSubview:web]; 
} 

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
[activity stopAnimating]; 
} 

- (void)webViewDidStartLoad:(UIWebView *)webView 
{  
[activity startAnimating]; 
} 
0

的順序添加子欣賞到超級觀點是顯著。 UIActivityIndicatorView被添加,然後UIWebView覆蓋它。如果添加的UIWebView第一,即

[self.view addSubview:web]; 
[self.view addSubview:activity]; 

UIActivityIndicatorView將覆蓋UIWebView

相關問題