How can I segue between two xib files in xamarin?

2019-09-16 02:06发布

问题:

I'm new to Xamarin and I'm working my way through an app. I'm also using mvvmCross. How can I segue between two views on button click? Normally I use storyboard so that's as simple as control+click and drag to hook it up. My second thought was to do something like:

PerformSegue(identifier, sender);

However, there's no way for me to set the identifier when i open the xib up to edit the interface.

So I have two xib files, HomeView.xib and SecondView.xib. As well as two c sharp files HomeView.cs and SecondView.cs. HomeView has a button and I have control+dragged the IBAction into the c sharp and have a method buttonPressed() where I wish to segue into my secondView.

partial void ButtonPressed (Foundation.NSObject sender){
        //Insert Code to segue to SecondView.
    }

Thanks :)

EDIT: I found this piece of code:

 NSBundle.MainBundle.LoadNib("SecondView", this, null);

Which works, however a segue would still be preferable as it looks nicer

回答1:

Create 2 segues in your storyboard and set different identifier to each segue.

Then use

this.PerformSegue("TargetSegueIdentifier", this);