Created
May 5, 2012 16:47
-
-
Save troystribling/2603949 to your computer and use it in GitHub Desktop.
Load UIView from NIB
This file contains hidden or 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
#import "NSObject+Extensions.h" | |
@interface UIView (Extensions) | |
+ (UIView*)loadView:(Class)_viewClass; | |
@end | |
@implementation UIView (Extensions) | |
+ (UIView*)loadView:(Class)_viewClass { | |
NSString* nibName = [_viewClass className]; | |
UIView* view = nil; | |
NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; | |
NSEnumerator *nibEnumerator = [nibContents objectEnumerator]; | |
NSObject* nibItem = nil; | |
while ((nibItem = [nibEnumerator nextObject]) != nil) { | |
if ([nibItem isKindOfClass:_viewClass]) { | |
view = (UIView*)nibItem; | |
break; | |
} | |
} | |
return view; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment