我的应用程序需要使用instantiateViewControllerWithIdentifier - 为什么? [英] My app requires using instantiateViewControllerWithIdentifier - why?

查看:107
本文介绍了我的应用程序需要使用instantiateViewControllerWithIdentifier - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Storyboard文件添加到最初没有的应用程序中。出于某种原因,我不能得到,直到我加入到这个 didFinishLaunchingWithOptions 我的自定义的UIViewController能够正确显示:

I have added a Storyboard file to an app that initially had none. For some reason, I could not get my custom UIViewController to display correctly until I added this into didFinishLaunchingWithOptions:

ActivityViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"ActivityViewController"];

为什么我需要强制使用我的故事板? iOS模板项目(Single View,Master-Detail等)不需要这个。

Why do I need to force the use of my storyboard like this? The iOS template projects (Single View, Master-Detail etc) doesn't need this.


  • Xcode项目摘要→主要故事板已正确设置为MainStoryboard。

  • Interface Builder→Identity Inspector→Class已正确设置为ActivityViewController。

  • Interface Builder→Identity Inspector→Storyboard ID也设置为ActivityViewController,但这只是因为 instantiateViewControllerWithIdentifier 所需。

  • Xcode Project Summary→Main Storyboard is set correctly to "MainStoryboard".
  • Interface Builder→Identity Inspector→Class is correctly set to "ActivityViewController".
  • Interface Builder→Identity Inspector→Storyboard ID is also set to "ActivityViewController", but this is only because it's needed by instantiateViewControllerWithIdentifier.

推荐答案

如果设置是初始视图,则无需调用instantiateViewControllerWithIdentifier故事板中的ActivetyViewController上的Controller 。初始视图控制器将有一个指向它的箭头。

You do not need to call instantiateViewControllerWithIdentifier if you set Is Initial View Controller on your "ActivetyViewController" in the storyboard. The initial view controller will have an arrow pointing at it.

这篇关于我的应用程序需要使用instantiateViewControllerWithIdentifier - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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