简体   繁体   English

找不到Xamarin.iOS / UIViewController上的MonoTouch故事板Segue

[英]Xamarin.iOS / MonoTouch Storyboard Segue on UIViewController not found

The following situation in Xamarin.IOS/Monotouch applies: Xamarin.IOS / Monotouch中的以下情况适用:

  • I'm using two viewcontrollers, VCOne and VCTwo and I have assigned them two custom classes in XCode the Storyboard editor (MYVCOneClass and MyVCTwoClass). 我使用了两个视图控制器VCOne和VCTwo,并且在Storyboard编辑器的XCode中为它们分配了两个自定义类(MYVCOneClass和MyVCTwoClass)。
  • Then I drag a segue from VCOne (from the viewcontroller in the left listing) to the VCTwo viewcontroller instance in the editor part and select "Push". 然后,将segue从VCOne(从左侧列表中的viewcontroller)拖动到编辑器部分中的VCTwo viewcontroller实例,然后选择“推”。
  • I name the segue "OneToTwoSegue". 我将segue命名为“ OneToTwoSegue”。

My question 我的问题

When I perform the following call from a button click eventhandler in the VCOne class: 当我从按钮执行以下调用时,请单击VCOne类中的事件处理程序:

this.performSegue("OneToTwoSegue", this);

I get a runtime error saying that the OneToTwoSegue cannot be found on the MyVCOneClass object. 我收到一个运行时错误,指出在MyVCOneClass对象上找不到OneToTwoSegue。

Does anyone know why i cannot call this segue from code like this? 有谁知道我为什么不能从这样的代码中调用此segue? I know i've seen segues working when i link them to cell's, buttons and alike... 我知道当我将segue链接到单元格,按钮等时,我已经看到segue起作用了……

If you are doing a "push" segue, your first view controller needs to be the root view controller of a UINavigationController. 如果要进行“推送” segue,则第一个视图控制器必须是UINavigationController的根视图控制器。

So in your storyboard, drag and drop a UINavigationController, delete the tableview and the ViewController that's attached by default, and then make VCOne the root view controller (the same way you would make a segue - hold control and drag from the UINavigationController to the UIViewController and then click root view controller. 因此,在情节提要中,拖放一个UINavigationController,删除默认情况下附加的tableview和ViewController,然后使VCOne成为根视图控制器(就像您进行选择一样-按住控件并将其从UINavigationController拖动到UIViewController然后单击根视图控制器。

Your Segue should work fine after. 之后,您的Segue应该工作正常。 Just make sure that the UINavigationController is set as the first screen (that little arrow that points to the left should be moved from VCOne to the UINavigationController) 只需确保将UINavigationController设置为第一个屏幕(指向左侧的小箭头应从VCOne移至UINavigationController)

EDIT: I have uploaded a screenshot of a sample storyboard I created to demonstrate this to you. 编辑:我上传了一个示例演示图板的屏幕截图,我创建了该演示图板以向您展示。 VCOne is the root view controller of the Navigation Controller. VCOne是导航控制器的根视图控制器。 And there is a segue from VCOne to VCTwo called OneToTwoSegue. 从VCOne到VCTwo有一个名为OneToTwoSegue的segue。 With this, your code on your button click will work perfectly. 这样,单击按钮时的代码将完美运行。 塞格故事板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM