2010-03-25 64 views
0

这里我在活动的指标gettimg内存分配的问题,我的代码是:在iPhone SDK中获得内存分配ActivityIndi​​cator

- (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; } return self; }

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

另外我释放的progressInd中的dealloc尽管它已经示出在

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

在初始化内存分配。

任何人都可以帮助我解决这个问题。

任何人的帮助将大大受到赞赏。

+0

究竟是什么问题? – 2010-03-25 07:46:31

回答

0

你可以将它添加到容器视图之后(也应该)释放:

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

同为容器视图本身:

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

含视图将保留子视图为你,所以你可以在添加它后立即发布它。

相关问题