2010-03-25 4 views
0

Ici, je suis problème d'allocation de mémoire gettimg à l'indicateur d'activité et mon code est:obtenir l'allocation de mémoire à ActivityIndicator dans Iphone sdk

- (id)init { 
    if (self = [super init]) { 
     [email protected]"Release Details"; 
     contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
     contentView.backgroundColor = [UIColor clearColor]; 
     self.view = contentView; 
     [contentView release]; 
     CGRect frame = CGRectMake(0,0, 320,1500); 
     containerView = [[UIView alloc] initWithFrame:frame]; 
     webView = [ [UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
     webView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"background1.png"]]; 
     webView.delegate = self;   
     [containerView addSubview:webView]; 
     CGRect activityViewframe = CGRectMake(20,8,20, 20); 
     progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe]; 
     progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; 
     progressInd.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 

UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); [containerView addSubview: progressInd]; [progressInd startAnimating]; progressInd.hidden = NO; [progressInd stopAnimating]; [self.view addSubview: containerView]; isFetch = YES; } retournez-vous; }

-(void) displayInProgressRightBarButton 
{ 
    UIView* rightBarButtonView = [ [UIView alloc] initWithFrame:CGRectMake(270,5,45, 35)]; 
    [rightBarButtonView addSubview:progressInd]; 
    UIBarButtonItem* buttonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtonView]; 
    self.navigationItem.rightBarButtonItem = buttonItem; 
    [rightBarButtonView release]; 
    [buttonItem release]; 
} 
- (void)webViewDidStartLoad:(UIWebView *)webView 
{ 
    [self displayInProgressRightBarButton]; 
    [progressInd startAnimating]; 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
} 
- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    [progressInd stopAnimating]; 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
} 

Je a également publié le progressInd en dealloc montrant qu'il eventhough l'allocation de mémoire à

progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe]; 

dans initialisation.

Quelqu'un peut-il m'aider à résoudre ce problème?

L'aide de tous sera très appréciée.

+0

Quel est exactement le problème? –

Répondre

0

Vous pouvez (et devrait) libérer juste après l'avoir ajouté à la vue du conteneur:

[containerView addSubview:progressInd]; 
[progressInd release]; 

Même chose pour la vue conteneur lui-même:

[self.view addSubview:containerView]; 
[containerView release]; 

La vue contenant conservera la sous-vue pour vous, ainsi vous pouvez le libérer juste après l'avoir ajouté.

Questions connexes