Iphone 如何使用带有参数的UIButton释放/的父UIView?
我想知道是否有一种方法可以释放UIView,它不存在于通过子视图UIButton的特定函数之外。因为我无法通过iAction的按钮给出指向UIView的指针参数,所以我被卡住了Iphone 如何使用带有参数的UIButton释放/的父UIView?,iphone,Iphone,我想知道是否有一种方法可以释放UIView,它不存在于通过子视图UIButton的特定函数之外。因为我无法通过iAction的按钮给出指向UIView的指针参数,所以我被卡住了 - (IBAction)statsTemp1:(id)sender{ CGRect newSize = CGRectMake(0,13,322,434); UIView *overl = [[UIView alloc] initWithFrame:newSize]; [self.view addSubview:o
- (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,但不能事先创建它
谢谢您的帮助,我很感激:听起来您想从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.
这就成功了。非常感谢你!永远不会想到UIView*overl=[self.view viewWithTag:99];[上覆从SuperView移除];