I'd like to design a UIView and some sub-views (UIWebView, UIToolbar, some UIBarButtonItems, a progress indicator and so-forth) using the Interface Builder, but I think it's unnecessary to do this traditionally, by using a UIViewController, using presentViewController:animated
etc.
So, I created a custom class, with the .h
file code as follows:
@interface FileInteractionManager : NSObject {
}
@property (nonatomic, retain) IBOutlet UIView *fileView;
@property (nonatomic, retain) IBOutlet UIWebView *fileWebView;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *printButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *optionsButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton;
My .m file is as follows:
@implementation FileInteractionManager
@synthesize fileView, fileWebView, doneButton, optionsButton, printButton;
-(id)init {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FileInteractionView" owner:self options:nil];
NSLog(@"Load success!");
return self;
}
Finally, I create a stand-alone xib file named 'FileInteractionView.xib', change the file's owner to the custom class I created above, and wire up the IBOutlets.
When I call the init
method on my class, I can see in the debugger that all my IBOutlet objects are instantiated properly.
My questions are:
Is the
loadNibNamed:owner:options:
method the right way to load my stand-alone .xib file? I don't like the fact that this method returns an array I have no use for (the top-level object returned matches my variablefileView
, but I've already linked them through the Interface Builder).Is my general approach correct in solving my problem? I carried out the above steps because I wanted a simple
UIView
object that I could add to my existing UIViewController, rather than present and dismiss a whole new UIViewController.