0

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

4 回答 4

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];   
}
于 2012-10-16T09:31:31.527 回答
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];
}
于 2012-10-16T09:30:49.210 回答
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]; 
    }
于 2012-10-16T09:31:00.963 回答
0

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

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

UIActivityIndicatorView覆盖UIWebView.

于 2012-10-16T09:40:17.057 回答