【问题标题】:Remove added viewControllers view using removeFromSuperview all at once使用 removeFromSuperview 一次性删除添加的 viewControllers 视图
【发布时间】:2014-03-27 11:21:50
【问题描述】:

我以下列方式添加了viewcontrollers

在第一个viewController:

[self.view addsubview:secondViewcontroller.view];

然后在第二个viewController:

[self.view addsubview:thirdViewcontroller.view];

然后在第三个viewController

[self.view addsubview:fourthViewcontroller.view];

现在我在fouthViewcontroller 并想使用removeFromSuperview 方法回到firsiViewController

我们怎样才能做到这一点?有没有其他方法可以做到这一点。我不想使用UINavigationController

【问题讨论】:

标签: ios7 uiview xcode5


【解决方案1】:

试试下面的代码,它可能会工作

NSArray * subviews = [self.view subviews];
    int cnt = [subviews count];
    for(int j=cnt-1; j >=0 ; --j )
    {
        UIView * sview = [subviews objectAtIndex:j];
        [sview removeFromSuperview];
    }

【讨论】:

    【解决方案2】:

    一行

    [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多