我在纸上想做的事情听起来很简单,但实际上做起来有困难
所以我在这个有导航 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);
最佳答案
好的,我设法通过这样的事件做到了这一点:
在父 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 ();
}
}
}
然后看起来像这样:
关于c# - 从 ScrollView ( subview )内部将 View 推送到导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034850/