c# - 从 ScrollView ( subview )内部将 View 推送到导航 Controller

标签 c# ios xamarin navigation xamarin.ios

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

所以我在这个有导航 Controller 的 View 中。在这个 View 中有一个 ScrollView ,我正在向它推送一个 subview 。

        // 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 上,我有一个按钮,我希望它将 View 推送到它的父 View (主视图)的 NavigationController。

我怎样才能做到这一点?

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

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

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

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

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

最佳答案

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

在父 View Controller 中:

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

关于c# - 从 ScrollView ( subview )内部将 View 推送到导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034850/

相关文章:

c# - 多列上的 SQLite ORM 主键

c# - SignalR 无法启动连接

ios - 如何以编程方式绕过 iOS 中的代理?

c# - 在现有 Xamarin.Forms 共享应用程序中实现 Prism

c# - 为什么 NUnit Android Test Runner 中的断言等于 0(零)?

c# - WPF ComboBox 和所选项目出现问题

c# - LINQ 到 SQL : Left join on multiple columns

ios - Xcode 找不到匹配的配置文件 - Ionic Cordova

ios - '(字符串)-> AnyObject ?' is not convertible to ' ResultCell'

ios - 尽管垂直对齐设置为中心,但 UITextField 是第一响应者时的文本要么被剪裁,要么出现在内容 View 的底部