Created
September 14, 2011 00:37
-
-
Save sbrocket/1215569 to your computer and use it in GitHub Desktop.
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
| // Uses a private internal subclass to allow for loading the view from within a NIB. | |
| // The subclass allows us to break the initialization loop that would otherwise occur. | |
| @interface SomeMyView__ : SomeMyView { | |
| } | |
| @end | |
| @implementation SomeMyView | |
| + (SomeMyView*)loadFromNib { | |
| NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"SomeMyView" owner:nil options:nil]; | |
| for (id obj in objects) { | |
| if ([obj isKindOfClass:[SomeMyView__ class]]) { | |
| return obj; | |
| } | |
| } | |
| assertLog(@"Couldn't find SomeMyView__ in objects instantiated from NIB!"); | |
| return nil; | |
| } | |
| - (id)initWithCoder:(NSCoder *)aDecoder { | |
| if ((self = [super initWithCoder:aDecoder])) { | |
| if ([[self class] isEqual:[SomeMyView class]]) { | |
| CGRect frame = self.frame; | |
| [self release]; | |
| self = [[SomeMyView loadFromNib] retain]; | |
| self.frame = frame; | |
| } | |
| } | |
| return self; | |
| } | |
| @end | |
| @implementation SomeMyView__ | |
| - (id)initWithCoder:(NSCoder *)aDecoder { | |
| self = [super initWithCoder:aDecoder]; | |
| return self; | |
| } | |
| @end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment