Created
December 24, 2013 11:51
-
-
Save Ramshandilya/8112211 to your computer and use it in GitHub Desktop.
A UIView category to load the view from XIB file
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
@interface UIView (LoadNib) | |
+ (id)loadInstanceFromNib; | |
+ (id)loadInstanceFromNibWithOwner:(id)owner; | |
@end |
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 "UIView+LoadNib.h" | |
@implementation UIView (LoadNib) | |
+ (id)loadInstanceFromNib | |
{ | |
UIView *result = nil; | |
NSArray *elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]; | |
for (id anObject in elements) { | |
if ([anObject isKindOfClass:[self class]]) { | |
result = anObject; | |
break; | |
} | |
} | |
return result; | |
} | |
+ (id)loadInstanceFromNibWithOwner:(id)owner | |
{ | |
UIView *result = nil; | |
NSArray *elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:owner options:nil]; | |
for (id anObject in elements) { | |
if ([anObject isKindOfClass:[self class]]) { | |
result = anObject; | |
break; | |
} | |
} | |
return result; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment