代码之家  ›  专栏  ›  技术社区  ›  ingh.am

删除UIView

  •  4
  • ingh.am  · 技术社区  · 14 年前

    所以我有一个名为 MainViewController 当我按下这个按钮时,它被称为:

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

    这带来了一种新的观点,这种观点非常有效。但是,如何从其中的按钮中删除此视图?在我不久前编写的一个应用程序中,我只是在 主视图控制器 打电话 RemoveView 在XIB文件中 NewViewController 我选择了 FirstResponder 然后 移除视图 为了那个按钮。这是可行的,但我不能在我的新项目中复制它,也不知道它是如何工作的!

    我要找的不是remove视图代码,而是从另一个类调用方法的方法。

    如果有人能帮我,那就太好了!:)

    谢谢

    1 回复  |  直到 14 年前
        1
  •  2
  •   GendoIkari    14 年前

    在Interface Builder中画线与调用

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

    操作需要是一个定义为 IBAction .

    对于您的情况,在NewViewController.h中,声明

    - (IBAction)removeView;
    

    然后在NewViewController.m中:

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

    在NeWVIEW .XB文件中,您应该能够拖动从您绘制到UIButton的所有者的行,并选择 removeView 行动。