删除一个UIView

问题描述:

所以我有一个按钮,当我按下这个代码被称为所谓的MainViewController一个视图控制器:删除一个UIView

NewViewController *newViewController; 
newViewController = [[NewViewController alloc] initWithNibName:@"NewView" bundle:nil]; 
[self.navigationController.view addSubview:newViewController.view]; 
[newViewController release]; 

这使得其中的伟大工程的新观点。但是,如何从该按钮中删除此视图?在我刚才写的一个应用程序中,我简单地在MainViewController中创建了一个名为RemoveView的方法,在0123B的XIB文件中我选择了FirstResponder,然后是RemoveView作为按钮。这可行,但我不能在我的新项目中复制它,并且不知道它是如何工作的!

这不是我正在查找的移除视图代码,更多的是从另一个类中调用方法。

如果任何人都可以帮助我,这将是伟大的! :)

由于

绘制在界面生成的线做同样的事情作为调用

[theButton addTarget:theController action:@selector(theAction) forControlEvents:UIControlEventTouchUpInside]; 

theAction需要是与一类的IBAction中定义的方法。

对于你的情况,你NewViewController.h,声明

- (IBAction)removeView; 

然后在NewViewController.m:

- (void)removeView 
{ 
    [self.view removeFromSuperview]; 
} 

在你newView.xib文件,你应该能够拖动线从您绘制到文件所有者的UIButton中,然后选择removeView操作。

+0

你将如何设置`theController`? – 2010-11-22 21:54:29