Created
May 7, 2014 20:17
-
-
Save kaspermunck/1afd3ca724076244a40e to your computer and use it in GitHub Desktop.
An example of how loading a nib file with a custom view can be done
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
| // 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