-1

我目前正在将topViewControlleraUIView添加到我的rootViewController. 有什么方法可以在通过UIViews之前删除所有内容吗?rootViewControllerpopToRootViewContoller

4

5 回答 5

2

在返回操作中,键入以下代码:

for (UIView *subview in self.view.subviews) {
    [subview removeFromSuperview];
}

然后键入popToRootViewContoller.

于 2012-12-14T11:07:13.470 回答
1

viewWillDisappear您可以执行此任务时,当您离开时,rootViewController此方法将调用,因此您可以在此时删除您的视图。

-(void)viewWillDisappear:(BOOL)animated
{
    for (UIView *view in [self.view subviews]) {
        [view removeFromSuperview];
    }
}
于 2012-12-14T10:56:21.537 回答
1

viewWillAppear:在YourViewController的方法中添加这个

for (UIView *view in self.view.subviews) {
        [view removeFromSuperview];
    }

希望对你有帮助

于 2012-12-14T11:01:34.607 回答
0

试试这个:

-(void)viewWillAppear:(BOOL)animated
{
NSArray *subviews = [self.view subviews];


    for (UIView *subview in subviews) {

        [subview removeFromSuperview];

    }
}
于 2012-12-14T11:00:40.330 回答
0
[yourView removeFromSuperView]

但是当你弹出一个时添加subviews不会在那里UIViewController,所以我认为你不需要这样做

于 2012-12-14T11:06:58.937 回答