CoderWang CoderWang - 4 months ago 23
iOS Question

Crashing: storyboardWithName:

Using the following method to get storyboard instance:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboardName" bundle:nil];


I have noted that "If no storyboard resource file matching name exists, an exception is thrown with description: Could not find a storyboard named 'XXXXXX' in bundle....". I know it cannot be too careful to deal with the method.

My question is that is there any way to catch the exception and handle it manually.
Any directions?

Tom Tom
Answer
NSString *sbName = @"storyboardName";
UIStoryboard *sb;
@try {
     sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
}@catch (NSException *exception) {
     [self warnMissingStoryBoard:sbName];
     //handle here...
     return;
}
//use sb here...
Comments