iPhone中的UIActivityIndi​​catorView问题?

时间:2012-10-16 09:26:14

标签: iphone ios webview uiactivityindicatorview presentmodalviewcontroller

目前我在iphone应用程序中工作,使用UIWebView(显示在presentModelViewController中的网页)在屏幕上显示网页,然后我添加UIActivityIndi​​catorView以显示加载网址请求,但是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];   
}

4 个答案:

答案 0 :(得分:1)

<填充您的活动指示器查看您的webView,如下所示: -

 - (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];   
}

答案 1 :(得分: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];
}

答案 2 :(得分: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]; 
    }

答案 3 :(得分:0)

将子视图添加到超级视图的顺序非常重要。添加UIActivityIndicatorView,然后UIWebView覆盖它。如果先添加UIWebView,即

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

UIActivityIndicatorView将覆盖UIWebView