从滚动视图(子视图)内部将视图推送到导航控制器

时间:2016-05-04 18:01:03

标签: c# ios xamarin navigation xamarin.ios

我试图在纸上做的事情听起来很简单,但我实际上遇到了麻烦

所以我在这个有导航控制器的View中。在这个视图中,有一个滚动视图,我将子视图推送到它。

        // Setting the View inside the Scroll View //
        viewOffers.ContentSize = new CoreGraphics.CGSize(320f, 1100f);
        ShowOffersViewController vc = Storyboard.InstantiateViewController("ShowOffersView") as ShowOffersViewController;
        viewOffers.AddSubview (vc.View);

在SubView上,我有一个按钮,我希望它将视图推送到它的父视图(主视图)的NavigationController。

我怎样才能做到这一点?

到目前为止,我已尝试过:

ChequesViewController test = Storyboard.InstantiateViewController("ChequesView") as ChequesViewController;

// This     
ParentViewController.NavigationController.PushViewController(test, true);

// and this and neither work
NavigationController.PushViewController(test, true);

图片我尝试做的事情的例子: Logic

1 个答案:

答案 0 :(得分:1)

好的,我设法做了这样的事件:

在Parent ViewController中:

viewOffers.ContentSize = new CoreGraphics.CGSize(320f, 1100f);
ShowOffersViewController vc = Storyboard.InstantiateViewController("ShowOffersView") as ShowOffersViewController;
vc.ButtonPressed += () => {
    ChequesViewController test = Storyboard.InstantiateViewController("ChequesView") as ChequesViewController;
    NavigationController.PushViewController(test, true);
};
viewOffers.AddSubview (vc.View);

然后在ShowOffersViewController.cs中:

public partial class ShowOffersViewController : UIViewController
{
    public ShowOffersViewController (IntPtr handle) : base (handle)
    {
    }

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

        button.TouchUpInside += Button_TouchUpInside;
    }

    public delegate void ButtonPressedHandler();
    public event ButtonPressedHandler ButtonPressed;

    public void Button_TouchUpInside (object sender, EventArgs e)
    {
        if (ButtonPressed != null) {
            ButtonPressed.Invoke ();
        }
    }
}

然后看起来像这样:

enter image description here