如何在 xamarin 中的两个 xib 文件之间进行切换? [英] How can I segue between two xib files in xamarin?

查看:30
本文介绍了如何在 xamarin 中的两个 xib 文件之间进行切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Xamarin 的新手,我正在通过应用程序工作.我也在使用 mvvmCross.如何在单击按钮时在两个视图之间进行切换?通常我使用故事板,所以就像控制+单击并拖动以连接它一样简单.我的第二个想法是做类似的事情:

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);

但是,当我打开 xib 以编辑界面时,我无法设置标识符.

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

所以我有两个 xib 文件,HomeView.xib 和 SecondView.xib.以及两个 c 锐文件 HomeView.cs 和 SecondView.cs.HomeView 有一个按钮,我已经控制+将 IBAction 拖动到 c 尖,并且有一个方法 buttonPressed(),我希望在其中进入我的第二个视图.

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.
    }

谢谢:)

我找到了这段代码:

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

哪个有效,但是 segue 仍然更可取,因为它看起来更好

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

推荐答案

在故事板中创建 2 个 segue,并为每个 segue 设置不同的标识符.

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

然后使用

this.PerformSegue("TargetSegueIdentifier", this);

这篇关于如何在 xamarin 中的两个 xib 文件之间进行切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆