UIPopovercontroller Parent?

落爺英雄遲暮 提交于 2019-12-08 17:36:18

问题


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

BTW - parentViewcontroller doesn't work...

Thanks!


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/4951200/uipopovercontroller-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!