问题
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"];
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.
Checklist:
- 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
.
回答1:
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.

来源:https://stackoverflow.com/questions/16618173/my-app-requires-using-instantiateviewcontrollerwithidentifier-why