我創建了一個解開編程和做動作如何通過一個按鈕來消失的UIView點擊
{
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton1.frame = CGRectMake(20, 20, 80, 44);
[myButton1 setTitle:@"Click Me!" forState:UIControlStateNormal];
[myButton1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton1];
}
和IBAction爲我有一個UIView作爲這樣
- (IBAction)buttonClicked:(id)sender
{
CGRect myFrame = CGRectMake(0, 300, 100, 50);
UIView *myView = [[UIView alloc] initWithFrame:myFrame];
myView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:myView];
[myView release];
}
我現在想子視圖當用戶第二次按myButton1時子視圖必須消失。我怎樣才能做到這一點?
thanx Dipak。工作正常 – jason 2012-01-19 08:07:03