FirstViewController无法删除SecondViewController的子视图

时间:2012-07-12 03:07:55

标签: ios xcode uiviewcontroller ibaction

第一视图控制器

我正在使用UIStoryBoard来允许FirstViewController将第二个ViewController的视图添加为子视图。在删除子视图

  - (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

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

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

当我访问withDraw函数时,将删除SecondViewController的视图并返回firstViewController。但是,当我使用按钮访问 - (IBAction)btnMoveTo:(id)发送器功能时。它不起作用。什么都没发生。任何建议或帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

有效

- (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];
}

我通过指向其标识符添加了firstViewController的另一个实例。因此它将FirstViewController带回到顶部。