2011-03-14 2 views
0

J'essaye de charger mon WebView correctement dans le cadre de CGRect que j'ai établi, avec le activityIndicator fonctionnant.obtenir UIWebView pour charger dans CGRect correctement

Il charge en quelque sorte correctement quand je l'ai mis en place avec [self.view addSubview:webView]; mais l'indicateur d'activité n'apparaît pas. Lorsque je l'ai configuré avec webView.delegate = self;, l'indicateur d'activité apparaît, mais le webview couvre l'intégralité de l'écran lorsqu'il est chargé. J'ai un haut segmenté qui se cache alors.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    CGRect webFrame = CGRectMake(0.0, 50.0, 320.0, 318.0); 

    activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    [self.view addSubview:activityIndicator]; 
    activityIndicator.frame = CGRectMake(250, 250, 30.0, 30.0); 
    self.view.center = CGPointMake(160.0f, 190.0f); 
    activityIndicator.center = self.view.center; 

    webView = [[UIWebView alloc] initWithFrame:webFrame]; 

    [webView setBackgroundColor:[UIColor whiteColor]]; 
    NSString *urlAddress = @"http://www.google.com"; 
    NSURL *url = [NSURL URLWithString:urlAddress]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [webView loadRequest:requestObj]; 
    webView.delegate = self; 
// [self.view addSubview:webView]; 
} 

- (void)webViewDidStartLoad:(UIWebView *)webView { 
    NSLog(@"activity started"); 
    [activityIndicator startAnimating]; 
} 
- (void)webViewDidFinishLoad:(UIWebView *)webView { 
    NSLog(@"activity stopped"); 
    [activityIndicator stopAnimating]; 
    self.view = webView; 
} 

Répondre

2

Il devrait être

- (void)webViewDidFinishLoad:(UIWebView *)webView { 
    NSLog(@"activity stopped"); 
    [activityIndicator stopAnimating]; 
    [[self view] addSubView:webView]; 
} 

Les vues n'étaient pas couverts, ils étaient retirés de la hiérarchie en remettant à zéro la propriété de la vue.

+0

merci génial, cela a fonctionné! – Aaron

Questions connexes