代碼: RootViewController.m ...
代碼:
RootViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title=@"removeFromSuperView";
UILabel *tryLabel=[[UILabel alloc]initWithFrame:CGRectMake(50, 150, 200, 50)];
tryLabel.backgroundColor=[UIColor redColor];
[self.view addSubview:tryLabel];
}
//當點擊任意處時,把UILabel去掉
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self removeFromView];
}
-(void)removeFromView
{
//點擊後刪除之前的PickerView
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[UILabel class]]) {
[view removeFromSuperview];
}
}
}
