An example of how loading a nib file with a custom view can be done
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
// UIView+KHMNibLoading.h | |
@interface UIView (KHMNibLoading) | |
+ (instancetype)viewFromNib; | |
@end | |
// UIView+KHMNibLoading.m | |
+ (instancetype)viewFromNib { | |
NSString *className = NSStringFromClass([self class]); | |
NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:className owner:self options:nil]; | |
id view = nil; | |
for (id object in bundle) { | |
if ([object isKindOfClass:[self class]]) { | |
view = object; | |
} | |
} | |
NSAssert(view != nil, @"Failed attempt to load %@ from nib", className); | |
return view; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment