ios - 从 Xamarin 中的代码隐藏创建 UIViewController

标签 ios uiviewcontroller xamarin segue code-behind

我目前正在使用 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/

相关文章:

android - 带有 AndroidSDK API 19 及更低版本的 Xamarin.Android 的放大 float 操作按钮的阴影填充错误

c# - Xamarin 中的自定义对话框宽度和高度

html - iOS 不尊重 z-index 与 -webkit-overflow-scrolling

ios - 使用 iAd 展示广告,不使用 Storyboard 或 Xib

ios - swift 2.0 : How do I specify which Annotation is pressed when having more then one Annotation? 市场

xcode - 无法将类型 'UINavigationController' (0x10836e698) 的值转换为 'UITabBarController' (0x10836e6e8)。?

ios - Swift - 获取 ipv6 链接本地地址?

swift - iPhone SE 尺寸屏幕的 Xcode 自动布局问题

ios - 这个花哨的 iOS 登录对话框是标准组件吗?

c# - 如何获取Xamarin Android项目的卫星数量