简体   繁体   中英

Xamarin.iOS / MonoTouch Storyboard Segue on UIViewController not found

The following situation in Xamarin.IOS/Monotouch applies:

  • I'm using two viewcontrollers, VCOne and VCTwo and I have assigned them two custom classes in XCode the Storyboard editor (MYVCOneClass and 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".
  • I name the segue "OneToTwoSegue".

My question

When I perform the following call from a button click eventhandler in the VCOne class:

this.performSegue("OneToTwoSegue", this);

I get a runtime error saying that the OneToTwoSegue cannot be found on the MyVCOneClass object.

Does anyone know why i cannot call this segue from code like this? I know i've seen segues working when i link them to cell's, buttons and alike...

If you are doing a "push" segue, your first view controller needs to be the root view controller of a 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.

Your Segue should work fine after. 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)

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. And there is a segue from VCOne to VCTwo called OneToTwoSegue. With this, your code on your button click will work perfectly. 塞格故事板

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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