I would like to create a UIView and some subviews (UIWebView, UIToolbar, some UIBarButtonItems, progress indicator, etc.) using Interface Builder, but I think it is not necessary to do this traditionally using the UIViewController using presentViewController:animated and etc.
So, I created my own 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 looks like this:
@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 standalone xib file named "FileInteractionView.xib", change the owner of the file to the user class that I created above, and enable IBOutlets.
When I call the init method in my class, I can see in the debugger that all my IBOutlet objects are created correctly.
My questions:
Is the loadNibNamed:owner:options: method the correct way to load my standalone .xib file? I do not like the fact that this method returns an array for which I do not use (the returned top-level object matches my fileView variable, but I already linked them using Interface Builder).
Is my general approach right when solving my problem? I followed the above steps because I need a simple UIView object that I could add to an existing UIViewController, instead of representing and rejecting the whole new UIViewController.
source share