删除子视图并发回控制权

Remove subview and send control back

我正在使用以下代码从 UIViewController 调用 "HelpviewController",它工作正常。

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InnerHelpPageViewController"];
            self.pageViewController.dataSource = self;

            InnerHelpViewController *startingViewController = [self viewControllerAtIndex:0];
            NSArray *viewControllers = @[startingViewController];
            [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

            // Change the size of page view controller
            self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);

            [self addChildViewController:_pageViewController];
            [self.view addSubview:_pageViewController.view];
            [self.pageViewController didMoveToParentViewController:self];

在我的新控制器中 InnerHelpViewController 我已经完成了按钮,它应该删除这个新添加的视图并将控制发送回启动的页面。

- (IBAction)unwindToMenuFromInnerHelp:(id)sender {
    [self.view removeFromSuperview];
}

这个调用删除了新添加的视图,但问题是"MenuController"被冻结了。我无法对其进行任何点击。有帮助吗?

为了解释流程 --> 我有一个菜单屏幕,其中一个按钮的名称为 "help" --> 当用户单击此帮助按钮时,此问题中的第一段代码将执行并显示 HelpViewController-->Once在帮助下完成,用户单击 "Done" 按钮--> 应该关闭 HelpViewController 并移动到 "menu" 屏幕。

在InnerHelpViewController.h文件中实现协议方法class

@protocol InnerHelpViewControllerDelegate

  -(void)removeCustomView;
@end

@interface InnerHelpViewController : UIViewController{

}
@property(nonatomic, weak) id<InnerHelpViewControllerDelegate> delegate.

在InnerHelpViewController.m文件中

@synthesize delegate;

- (IBAction)unwindToMenuFromInnerHelp:(id)sender {
    [delegate removeCustomView];
}

在 MenuController.h 文件中采用 InnerHelpViewControllerDelegate。

@interface MenuController : UIViewController<InnerHelpViewControllerDelegate>{

}

现在在创建 helpviewcontroller 对象时在 MenuController.m 文件中确认您的委托。

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InnerHelpPageViewController"];
            self.pageViewController.dataSource = self;

            InnerHelpViewController *startingViewController = [self viewControllerAtIndex:0];
            startingViewController.delegate = self;
            NSArray *viewControllers = @[startingViewController];
            [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

            // Change the size of page view controller
            self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);

            [self addChildViewController:_pageViewController];
            [self.view addSubview:_pageViewController.view];
            [self.pageViewController didMoveToParentViewController:self];

//Implement here delegate method
     -(void)removeCustomView{
      [self.pageViewController removeFromSuperview]
    }