简体   繁体   English

FirstViewController不适用于删除SecondViewController的子视图

[英]FirstViewController doesn't work on removing the subview of SecondViewController

First View Controller 第一视图控制器

I'm using a UIStoryBoard to allow the FirstViewController to add the view of second ViewController as a subview. 我正在使用UIStoryBoard允许FirstViewController将第二个ViewController的视图添加为子视图。 On removing the sub view the 在删除子视图时

  - (IBAction) btnMoveTo:(id)sender
{

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Second"];
 vc.view.backgroundColor = [UIColor clearColor];
 self.modalPresentationStyle = UIModalPresentationCurrentContext;
 [self presentModalViewController:vc animated:NO];

}

SecondViewController.m SecondViewController.m

-(void)viewDidLoad{
   self.view.opaque = YES;
   self.view.backgroundColor = [UIColor clearColor];
}

 - (IBAction) withDraw:(id)sender{
     [self.view removeWithZoomOutAnimation:2 option:nil];
    }

When I access the withDraw Function, the view of the SecondViewController is removed and firstViewController is back. 当我访问withDraw函数时,SecondViewController的视图将被删除,并且firstViewController将返回。 However when I use the button to access the - (IBAction) btnMoveTo:(id)sender function. 但是,当我使用按钮访问-(IBAction)btnMoveTo:(id)sender函数时。 It doesn't work. 没用 Nothing really happens. 真的什么都没发生。 Any suggestions or help would be greatly appreciated. 任何建议或帮助将不胜感激。

也许您可以尝试这样声明* vc:UIViewController * vc = [self.storyboard InstantiateViewControllerWithIdentifier:@“ Second”];

It worked 有效

- (IBAction) withDraw:(id)sender{
 [self.view removeWithZoomOViewControllerutAnimation:2 option:nil];

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
  UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"First"];
  vc.view.backgroundColor = [UIColor clearColor];
  self.modalPresentationStyle = UIModalPresentationCurrentContext;
  [self presentModalViewController:vc animated:NO];
}

I added another instance of the firstViewController by pointing to its identifier. 我通过指向其标识符添加了firstViewController的另一个实例。 So it brings back FirstViewController to the top. 因此,它将FirstViewController带回到顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UITextField在我的SecondViewController中不起作用 - UITextField doesn't work in my SecondViewController FirstViewController在另一个SecondViewController上,可单击SecondViewController - FirstViewController over another SecondViewController where SecondViewController is clickable 在启动插入FirstViewController时打开SecondViewController - Open SecondViewController on startup insted FirstViewController 在FirstViewController中单击按钮时在SecondViewController中显示图像 - Show image in SecondViewController when button is clicked in FirstViewController 如何在不单击任何按钮的情况下将firstViewController导航到secondViewController - How to navigate firstViewController to secondViewController without click anybutton 在Swift中从SecondViewController从FirstViewController访问变量 - Accessing Variables from FirstViewController from SecondViewController in Swift 从Iphone中的SecondViewController显示一个方法的FirstViewController On Call - To show A FirstViewController On Call of a method from SecondViewController in Iphone 如何从SecondViewController修改FirstViewController中的UITextField? - How to modify UITextField in FirstViewController from SecondViewController? 翻转两个子视图不能连续工作 - flip two subview doesn't work continuosly UIButton作为MKAnnotationView中的子视图不起作用 - UIButton as a subview in MKAnnotationView doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM