2010-03-25 65 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]; 

含視圖將保留子視圖爲你,所以你可以在添加它後立即發佈它。

相關問題