开发者

iPhone - Accessing the parent viewcontroller?

开发者 https://www.devze.com 2023-02-03 21:59 出处:网络
I have 2 viewcontrollers A, B ViewController A is being displ开发者_如何转开发ayed on the screen

I have 2 viewcontrollers A, B

  1. ViewController A is being displ开发者_如何转开发ayed on the screen
  2. The view of ViewController B is added to the view of ViewController A.

How can i access ViewController A from ViewController B without passing a pointer?

self.parentViewController does not work it returns nuil


Why is the view of viewController B added to the view of viewController A? If you are meaning to add a view to viewController A, you can do that by allocating a new UIView and displaying that on top of the current view.

On the other hand if you are trying to transition from one view controller to another, i.e going from A to B and then back to A, you should use a UINavigationController as specified in the View Controller Programming Guide in the Apple Documentation.

Source: View Controller Programming Guide

EDIT: If you want to use [[self parentViewController] yourMethodHere]; you will need a view hierarchy, for which you can use the UINavigationController. In your current scheme there is no hierarchy built so there is no parent view controller.


This should work though its not very elegant:

UIViewController* viewControllerA = 
    (UIViewController*) [[self.view superview] nextResponder];
0

精彩评论

暂无评论...
验证码 换一张
取 消