开发者

UIPopovercontroller Parent?

开发者 https://www.devze.com 2023-02-09 08:32 出处:网络
How can \"perform selector\" to the parentviewcontroller of the uipopovercontroller? I have uipopovercontroller lanuched from uiviewcontroller, and this uipopovercontroller includes other uiviewcontro

How can "perform selector" to the parentviewcontroller of the uipopovercontroller? I have uipopovercontroller lanuched from uiviewcontroller, and this uipopovercontroller includes other uiviewcontroller. I can't seem to reach the parent view controller from either the popover or the "internal" view controller.

I hope i'm being clear...

B开发者_StackOverflowTW - parentViewcontroller doesn't work...

Thanks!


There's no way to do this directly with UIPopoverController. You're going to have to probably pass a reference to your parent view controller to the view controller you're managing with a popover controller:

// Assumes these calls are made from within a view controller and that
// MyViewController has a property called previousViewController

MyViewController * myViewController = [[[MyViewController alloc] init] autorelease];
myViewController.previousViewController = self;
UIPopoverController * popoverController = [[[UIPopoverController alloc] 
    initWithContentViewController:myViewController] autorelease];

UIBarButtonItem * rightBarButtonItem = self.navigationItem.rightBarButtonItem;
[popoverController presentPopoverFromBarButtonItem:rightBarButtonItem
                          permittedArrowDirections:UIPopoverArrowDirectionDown
                                          animated:YES];

Something like that, but the important point is that your view controller (managed by the popover controller) has to grab a reference to your parent view controller before you present the popover.


You can use a private method to get a parent popover controller from the view controller.

UIPopoverController *popopverController = [self performSelector:@selector(_popoverController)];
[popopverController dismissPopoverAnimated:YES];
0

精彩评论

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