【问题标题】:Push a View to a Navigation Controller from inside a scroll view (subview)从滚动视图(子视图)内部将视图推送到导航控制器
【发布时间】:2016-05-04 18:01:02
【问题描述】:

我想在纸上做的事情听起来很简单,但实际上我很难做到

所以我在这个有导航控制器的视图中。在这个视图里面有一个滚动视图,我正在向它推送一个子视图。

        // 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);

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

我怎样才能做到这一点?

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

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

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

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

我正在尝试做的图片示例:

【问题讨论】:

  • 你想让你推送的视图成为导航控制器的子视图,还是滚动视图的子视图?
  • 我希望它推送到它的父导航控制器。澄清一点:[带导航控制器的父视图]-> [带有推送子视图的滚动视图]->按下内部按钮,将视图推送到父导航控制器
  • 好的,明白了。因此,您遇到的麻烦是找到从滚动视图中引用导航控制器的正确方法。我不是 Xamarin 人,所以我不确定我能帮上什么忙,但是如果你设置断点,你至少能找到滚动视图的 ViewController 的引用吗?如果是这样,那就是scrollViewsViewController.NavigationController
  • 没问题的人,我真的很感谢你的帮助。这是我正在尝试做的一个模拟示例。我的英语有点不确定(第二语言),但希望这能很好地解释。 oi63.tinypic.com/o527m8.jpg
  • 您好,您这样做了还是我错过了您的导航?

标签: c# ios xamarin navigation xamarin.ios


【解决方案1】:

好的,我设法通过这样的事件做到了这一点:

在父视图控制器中:

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 ();
        }
    }
}

然后看起来像这样:

【讨论】:

  • 很棒的人,我相信它会奏效的!我会在早上尝试第一件事。再次感谢!
  • 不用担心,告诉我进展如何
猜你喜欢
  • 2014-09-17
  • 2016-10-22
  • 2014-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多