从任何其他类的控制器中删除视图?

时间:2016-08-11 09:36:45

标签: ios objective-c xcode uinavigationcontroller

我有三个屏幕谷歌地图,设置,登录。默认谷歌地图是可见的。当我想显示设置屏幕,然后我没有移动到设置视图控制器我只是添加"设置&#34 ;屏幕为" Google Map" Screen。

的子视图
 menusettings=[self.storyboard instantiateViewControllerWithIdentifier:@"SET"];
 [menusettings.view setFrame:CGRectMake(0, 0, 700,600)];
 [self.view addSubview:menusettings.view];

提升设置后,我将移至登录界面

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
 UINavigationController *ppc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
[self presentViewController:ppc animated:true completion:nil];

但是设置屏幕仍在登录屏幕后面,但不会被删除。我尝试了两个场景

1.我试图在移动到登录屏幕之前删除设置视图

 [self.view removeFromSuperview];
 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"PRG_iPhone" bundle:nil];
 UINavigationController *ppc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
 [self presentViewController:ppc animated:true completion:nil];

但它不会移动到登录屏幕。

2.我在移动到登录屏幕后尝试删除设置视图

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"PRG_iPhone" bundle:nil];
     UINavigationController *ppc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
     [self presentViewController:ppc animated:true completion:nil];
     [self.view removefromsuperview];

然后它移动到登录屏幕,但不删除设置视图

所以我想为什么不从登录屏幕中删除Google地图屏幕的设置屏幕子视图,但我不知道如何删除一个谷歌地图屏幕子视图,这是设置屏幕。请指导如何操作?

1 个答案:

答案 0 :(得分:1)

更改此

[self.view removeFromSuperview];

来试试

[menusettings.view removeFromSuperview];

<强>更新

  [menusettings.view removeFromSuperview];
 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"PRG_iPhone" bundle:nil];
 UINavigationController *ppc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
 [self presentViewController:ppc animated:true completion:nil];

<强>选择-1

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

<强>选择-2

最初为您的View分配标签,例如

menusettings=[self.storyboard instantiateViewControllerWithIdentifier:@"SET"];
[menusettings.view setFrame:CGRectMake(0, 0, 700,600)];
 menusettings.tag = 5; //you can use any number you like
[self.view addSubview:menusettings.view];

删除

 UIView *Remove = [self.view viewWithTag:5];
[Remove removeFromSuperview];
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"PRG_iPhone" bundle:nil];
 UINavigationController *ppc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
 [self presentViewController:ppc animated:true completion:nil];

<强>选择-3

 for (UIView *subVie in self.view.subviews)
{
    if (subVie.tag == 5) 
    {
        [subVie removeFromSuperview];
    }
  }