代码:
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];
} } }