2010-12-19 11 views
0

サブビューUIButtonを介して特定の機能の外部に存在しないUIViewをリリースする方法があるのだろうかと思います。私はIBActionにUIViewのトラフにポインタのパラメータを与えることができないので、私は立ち往生しています。UIButtonの/の親UIViewをパラメータで解放するにはどうすればよいですか?

- (IBAction)statsTemp1:(id)sender{ 


CGRect newSize = CGRectMake(0,13,322,434); 
UIView *overl = [[UIView alloc] initWithFrame:newSize]; 
[self.view addSubview:overl]; 
[overl setBackgroundColor:[UIColor grayColor]]; 
[overl setAlpha:0.85]; 
[self doTheGraphIn:overl]; 
CGRect btnFrame = CGRectMake(150, 400, 30, 30); 
UIButton *closeStatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
closeStatButton.frame = btnFrame; 
[overl addSubview:closeStatButton]; 
[closeStatButton addTarget:self action:@selector(closeStat:) forControlEvents:UIControlEventTouchUpInside];}-(IBAction)closeStat:(id)sender{ 
[self release]; 
    } 
    -(IBAction)closeStat:(id)sender{ 
[overl release]; 
    } 

だけclaryfyする:私はボタンで(UIViewの*)overlをリリースしたいと事前にそれを作成することはできません。あなたの助けのための

おかげで、私はそれをapreciateだろう:)

答えて

0

あなたがself.viewからover1削除したいようですね。 (リリースを意味する)

トリックをやったこと

- (IBAction)statsTemp1:(id)sender{ 

// Create UIView 
    CGRect newSize = CGRectMake(0,13,322,434); 
    UIView *overl = [[UIView alloc] initWithFrame:newSize]; 
    [overl setBackgroundColor:[UIColor grayColor]]; 
    [overl setAlpha:0.85]; 
    [over1 setTag:99]; 

// Add UIButton to overl 
     CGRect btnFrame = CGRectMake(150, 400, 30, 30); 
     UIButton *closeStatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     closeStatButton.frame = btnFrame; 
     [overl addSubview:closeStatButton]; 
     [closeStatButton addTarget:self action:@selector(closeStat:) forControlEvents:UIControlEventTouchUpInside]; 

// Add overl to view 
    [self.view addSubview:overl]; 

// over1 can now be released because self.view has a pointer to it 
     [overl release]; 

// Do God knows what 
    [self doTheGraphIn:overl]; 

} 

// Remove overl from self.view 
-(IBAction)closeStat:(id)sender { 
    UIView *overl = [self.view viewForTag:99]; 
    [over1 removeFromSuperView]; 
    } 

// The UIButton is autorelease, so you should be good. 
+0

(そうご確認下さい、メモリから)...これを試してみてください。どうもありがとうございました!考えていないでしょう。 #:UIView * overl = [self.view viewWithTag:99]; [overl removeFromSuperview]; – dos

+0

まあ、あなたも私に投票を与えている可能性があります;) – Jordan

関連する問題