我目前正在使用 Xamarin 开发 IOS 应用程序。我制作了一个菜单,它从代码隐藏生成 4 个不同的 UIViewController。我想做的是将这些 View 推送到我在 Storyboard 中设计的预制 UIViewController,但未连接到当前 UIViewController。
像这样:
UIViewController[] control = new UIViewController[DataList.Count];
for (int i = 0; i < control.Length; i++)
{
if(control[i] == 1)
{
control[i] = new ViewControllerGetCar();
PerformSegue(control[i], null);
}
if(control[i] == 2)
{
}
}
无法将 ViewControllerGetCar 转换为 UIViewController... 它说需要 intPtr 句柄,但我不知道那是什么。我也很确定 performsegue 不会起作用。有什么想法吗?
最佳答案
如果您在 Storyboard 中设计了 ViewController,那么下面是实例化它们的正确方法。
MyViewController controller = MyViewController)this.Storyboard.InstantiateViewController("ViewControllerIdentifier");
翻译成你的例子:
UIViewController[] control = new UIViewController[DataList.Count];
for (int i = 0; i < control.Length; i++)
{
if(control[i] == 1)
{
control[i] = this.Storyboard.InstantiateViewController("ViewControllerGetCar"); // <-- presuming that's the identifier you're using for it inside the Storyboard.
PerformSegue(control[i], null);
}
if(control[i] == 2)
{
// presumably here another ViewController is specified, etc.
}
}
关于ios - 从 Xamarin 中的代码隐藏创建 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25419686/