Created
June 5, 2013 11:43
-
-
Save advantis/5713309 to your computer and use it in GitHub Desktop.
Fix for UIStoryboard unable to recognize device-specific resource names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Copyright © 2013 Yuri Kotov | |
// | |
#import <objc/runtime.h> | |
NS_INLINE NSString * DeviceSpecificSuffix(UIUserInterfaceIdiom idiom) | |
{ | |
switch (idiom) | |
{ | |
case UIUserInterfaceIdiomPhone: | |
return @"~iphone"; | |
case UIUserInterfaceIdiomPad: | |
return @"~ipad"; | |
default: | |
return @""; | |
} | |
} | |
// HACK: Fix for rdar://12753707 | |
@implementation UIStoryboard (ADVDeviceModifierSupport) | |
+ (void) load | |
{ | |
@autoreleasepool | |
{ | |
method_exchangeImplementations(class_getClassMethod(self, @selector(storyboardWithName:bundle:)), | |
class_getClassMethod(self, @selector(ADV_storyboardNamed:bundle:))); | |
} | |
} | |
+ (UIStoryboard *) ADV_storyboardNamed:(NSString *)name bundle:(NSBundle *)bundleOrNil | |
{ | |
UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom]; | |
NSString *deviceSpecificName = [name stringByAppendingString:DeviceSpecificSuffix(idiom)]; | |
NSBundle *bundle = bundleOrNil ?: [NSBundle mainBundle]; | |
if ([bundle pathForResource:deviceSpecificName ofType:@"storyboardc"]) | |
{ | |
name = deviceSpecificName; | |
} | |
return [self ADV_storyboardNamed:name bundle:bundleOrNil]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment