2010-12-19 2 views
0

Ich frage mich, ob es eine Möglichkeit gibt, eine UIView freizugeben, die nicht außerhalb einer bestimmten Funktion über eine Unteransicht UIButton existiert. Da ich nicht in der Lage bin, den Parameter des Zeigers auf die UIView über den Button der IBAction zu geben, stecke ich fest.Wie gebe ich eine übergeordnete UIView von/mit einem UIButton mit Parametern frei?

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

nur claryfy: Ich habe den (UIView *) overl mit der Taste freigeben mag, und es vorher nicht erstellen kann.

Danke für Ihre Hilfe, ich würde es apreciate :)

Antwort

0

Es klingt wie Sie over1 von self.view entfernen möchten. (Was bedeutet, Freigabe)

Try this ... (aus dem Gedächtnis, so überprüfen Sie bitte)

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

, die den Trick tat. vielen Dank! hätte nie gedacht .. #: UIView * overl = [self.view viewWithTag: 99]; [overl removeFromSuperview]; – dos

+0

Nun, Sie hätten mir auch eine Stimme geben können;) – Jordan

Verwandte Themen