Okay I just typed this whole question out and then managed to delete it. Sigh. Anyway, standard disclosure that I have searched everywhere and banged my head on the keyboard and can't figure this out.
I'm building a basic app based on the utility application template (with a MainViewController and FlipsideViewController). Side note: I still don't understand the purpose of MainView and FlipsideView in this scheme so if someone can explain it that wouldn't be too terrible :D
Anyway, at the bottom of both of these views I want to have a toolbar. It was easy enough to add that to a given view with IB, but I want the toolbar to have its own controller and model because I want to keep its state consistent across the two views. Accordingly I'd like to load that view from a nib but it seems I'm doing something wrong. I followed the advice here: http://stackoverflow.com/questions/1726250/nsviewcontroller-and-multiple-subviews-from-a-nib but obviously borked it up so more insight would be appreciated.
I did the following things: I created ToolBarViewController which is basically empty but is the file owner of ToolBar.xib. Inside ToolBar.xib I have a view with a frame the size of the toolbar and inside that a toolbar. In MainView.xib I've got a view element of the same size which is wired up to toolBarView found in the code below...
In MainViewController.h:
#import "ToolBarViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, MKMapViewDelegate> {
...
ToolBarViewController *toolBarViewController;
IBOutlet UIView *toolBarView;
}
...
@property(nonatomic, retain) ToolBarViewController *toolBarViewController;
@property(nonatomic, retain) IBOutlet UIView *toolBarView;
In MainViewController.m:
@synthesize toolBarViewController;
@synthesize toolBarView;
- (void)loadView
{
[super loadView];
toolBarViewController = [[ToolBarViewController alloc] initWithNibName:@"ToolBar" bundle:nil];
[[toolBarViewController view] setFrame:[toolBarView frame]];
[[self view] replaceSubview:toolBarView with:[toolBarViewController view]];
}
When I build and run I get the warning for the last line above that 'UIView' may not respond to 'replaceSubview:with' and on running it the following exception is thrown: * -[MainView replaceSubview:with:]: unrecognized selector sent to instance 0x450c540
Can anyone explain what I'm doing wrong? Thanks!å