我以编程方式将UIButton,UITextView作为子视图添加到了我的视图中。如何删除子视图
notesDescriptionView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,460)];
notesDescriptionView.backgroundColor=[UIColor redColor];
[self.view addSubview:notesDescriptionView];
textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,320,420)];
[self.view addSubview:textView];
printf("\n description button \n");
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button
addTarget:self action:@selector(cancel:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"OK" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 420.0, 160.0, 40.0);
[self.view addSubview:button];
这里,如果我们按一下按钮,我需要删除所有的子观点,
我试图
[self.view removeFromSuperView]
,但它不工作
任何帮助。
按钮,我已创建,通过添加为子视图。 实际上我试图用textview显示一个视图,当按下按钮时,当我点击当前视图中的另一个按钮时,它必须回到我以前的视图。 – mac 2010-06-09 12:28:27
我试过 [notesDescriptionView removeFromSuperview]; [textView removeFromSuperview]; 但它不工作。 – mac 2010-06-09 12:37:49
什么是正确的方式来调用这种方法,从其他类的超级视图中删除子视图?我试图委托方法,但它不起作用。 – SanitLee 2016-09-26 01:23:30