我目前正在开发Xamarin的IOS应用程序。我做了一个菜单,从代码隐藏生成4个不同的UIViewControllers。我想要做的是将这些视图推送到我在故事板中设计的预制UIViewControllers,但是没有连接到当前的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句柄是必需的,我不知道那是什么。我也很确定表演不会奏效。有什么想法吗?
答案 0 :(得分:2)
如果您在Storyboard中设计了ViewControllers,那么这是实例化它们的正确方法。
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.
}
}