如标题所述,我想从UIPopoverController中托管的现有UIViewController中显示另一个UIViewController。我尝试了以下方法:

_secondViewController = new SecondViewController();
this.ModalPresentationStyle = UIModelPresentationStyle.CurrentContext;
this.ModelInPopover = true;
this.PresentModelViewController(_secondViewController, true);

但是,secondViewController会显示在主 View Controller 中,而不是弹出窗口 Controller 中。

在此post中,有人提到它无法完成,并且违反了HIG。但是,如果我没有记错的话,我已经在其他应用程序(例如Yahoo! Email)中看到了这一点。

我还在考虑另一种方法:如果可以在弹出上下文中创建UINavigationController,则可以通过将新的ViewController添加到NavigationController来实现。但是如何?

最佳答案

请记住,UINavigationController派生自UIViewController。

因此,您可以像使用其他任何容器一样使用UIPopover中包含的 Controller ...在这种情况下,最好在UIPopover中使用UINavigationController来显示ViewControllers。

用法:

var _NavController = new NavController();

Popover = new UIPopoverController(_NavController);
Popover.PopoverContentSize = new SizeF(..., ...);

Popover.PresentFromRect(...);

导航 Controller :
public class NavController : UINavigationController
{
    UIViewController _FirstViewController;
    UIViewController _SecondViewController;

    public NavController()
        : base()
    {
    }

    public override void LoadView()
    {
        base.LoadView();

        _FirstViewController = new UIViewController();

        // Initialize your originating View Controller here.
        // Only view related init goes here, do everything else in ViewDidLoad()
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        // When a button inside the first ViewController is clicked
        // The Second ViewController is shown in the stack.

        _FirstViewController.NavButton.TouchUpInside += delegate {
            PushSecondViewController();
        };

        this.PushViewController(_FirstViewController, true);
    }

    public void PushSecondViewController()
    {
        _SecondViewController = new UIViewController();
        this.PushViewController(_SecondViewController, true);
    }
}

关于ipad - 适用于iPad的MonoTouch : How to show another UIViewController in a UIPopoverController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8198644/

10-13 04:16
查看更多