如何从子视图访问ParentViewController方法?

Hur*_*rkS 1 objective-c subview uiviewcontroller uiview ios

我已经创建了一个方法来调用a UIViewControllersubview像这样加载它

cameraViewController = [[CameraViewController alloc] init];
        cameraViewController.view.frame = CGRectMake(0.0, 0.0, screenHeight, screenWidth);
        [cameraViewController drawCameraView:htmlProjID ProjectGUID:selectedProjGUID DoorGUID:cell.currentItem.doorGUID Info:nil doorName:cell.currentItem.doorDesc ViewName:@"Finishing"];
        [self.view addSubview:cameraViewController.view];
Run Code Online (Sandbox Code Playgroud)

我想知道是否有一种简单的方法可以camerViewController从原始的(子视图)访问方法UIViewController

小智 5

也许这将返回你想要的东西:

 id mainViewController = [self.view.superview nextResponder];
Run Code Online (Sandbox Code Playgroud)

Apple的文档 - [UIResponder nextResponder]:

UIView通过返回管理它的UIViewController对象(如果有的话)或超级视图(如果没有)来实现此方法

除此之外,您可以从这里获得想法.