从滚动视图(子视图)内部将视图推送到导航控制器
Push a View to a Navigation Controller from inside a scroll view (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 上,我有一个按钮,我希望它将视图推送到它的父视图(主视图)的 NavigationController。
我怎样才能做到这一点?
到目前为止我已经尝试过:
ChequesViewController test = Storyboard.InstantiateViewController("ChequesView") as ChequesViewController;
// This
ParentViewController.NavigationController.PushViewController(test, true);
// and this and neither work
NavigationController.PushViewController(test, true);
我正在尝试做的事情的图片示例:
好的,我设法通过这样的事件做到了这一点:
父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 ();
}
}
}
然后看起来像这样:
我想在纸上做的事情听起来很简单,但实际上做起来有困难
所以我在这个有导航控制器的视图中。在这个视图中有一个滚动视图,我正在向它推送一个子视图。
// 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);
我正在尝试做的事情的图片示例:
好的,我设法通过这样的事件做到了这一点:
父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 ();
}
}
}
然后看起来像这样: