Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashes when instantiating view controller from storyboard

I am implementing time-out action for my app. I referred this stackoverflow thread iOS perform action after period of inactivity (no user interaction) and did follow exactly the same approach but my app crashes when it is about to transition to a new view controller over here

UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL];

UIViewController *cont = [myStoryboard instantiateViewControllerWithIdentifier:@"abc"];

I have given the name abc in my Storyboard file under Storyboard ID. Is there any other way to load a view controller ? What is wrong with this ? Why is my app crashing ?

This is the crash message from console:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle"

I don't have .xib file associated with this controller I am trying to load. I just have abc.h and abc.m files. But in my storyboard file, I have a bunch of view controllers and in there, I have specified the class of one of the view controllers as "abc". Isn't it enough ? Or else, what is the best way to load my view controller ? using segue ?

like image 450
user1982519 Avatar asked Jul 15 '13 17:07

user1982519


1 Answers

Regarding your exception - your storyboard is probably not copied to the main bundle. See this.

Also, the method instantiateViewControllerWithIdentifier uses the Storyboard ID defined in the Storyboard itself and not the name of the view controller. See this for more information on how to instantiate a specific view controller from a storyboard, or use the instantiateInitialViewController if you want to initialize the initial view controller (the one that is pointed by an arrow in your storyboard).

Edit: the exception is raised because of a bug in iOS where storyboards with name modifier, such as Storyboard_ipad and Storyboard_iphone cause a confusion in an internal iOS mechanism inside [UIStoryboard storyboardWithName:bundle:]. The solution is to avoid using this naming convention and possibly write a helper function to choose a storyboard name to load by examining the current device idiom.

like image 126
StatusReport Avatar answered Nov 15 '22 05:11

StatusReport