Please forgive me as this question has been asked 100 times on here (and I promise that I've read every thread!), but I simply can't figure out how to correctly load a NIB file into a UIView. I tried two approaches (seen below), though neither seemed to work for me. I have a UINavController/UIViewController setup and I'm trying to load a subclassed UIView into a small area on one of these UIViewControllers.
This answer seemed reasonable, but i can't seem to get it to work: iPhone - Load a UIView from a nib file?
// ViewController.m
localAssetUpdater = [[LocalAssetUpdater alloc] initWithFrame:[self.view frame]];
// LocalAssetUpdater.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"LocalAssetUpdater" owner:self options:nil];
[self reset];
[self beginLoad];
}
return self;
}
//OR:
// ViewController.m
localAssetUpdater = [LocalAssetUpdater myView];
// LocalAssetUpdater.m
+ (LocalAssetUpdater *) myView
{
NSArray* array = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil];
return [array objectAtIndex:0]; // assume that MyView is the only object in the xib
}