I'm running into a minor complication using IBInspectable properties and not sure if it might have something to do with my xibs and xib usage. I'm trying to reuse a custom control between multiple view controllers. The control is a custom tab manager:
The IBInspectable Attributes are configured in this xib as: First, Second, Third.
Here is the corresponding code for the header file.
IB_DESIGNABLE
@interface TabContainerView : NSView
@property (nonatomic, strong) IBOutlet NSView *view;
@property (weak) IBOutlet TabContentView *contentView;
@property (weak) IBOutlet TabView *firstTab;
@property (weak) IBOutlet TabView *secondTab;
@property (weak) IBOutlet TabView *thirdTab;
@property (nonatomic, strong) IBInspectable NSString *tabOneText;
@property (nonatomic, strong) IBInspectable NSString *tabTwoText;
@property (nonatomic, strong) IBInspectable NSString *tabThreeText;
@end
#import "TabContainerView.h"
@interface TabContainerView ()
@property (nonatomic, strong) NSMutableArray *tabsArray;
@property (nonatomic, assign) NSInteger selectedTabIndex;
@property (weak) IBOutlet NSTextField *tabOneTextField;
@property (weak) IBOutlet NSTextField *tabTwoTextField;
@property (weak) IBOutlet NSTextField *tabThreeTextField;
@end
@implementation TabContainerView
#pragma mark Init
- (id)initWithFrame:(NSRect)frameRect {
NSString* nibName = NSStringFromClass([self class]);
self = [super initWithFrame:frameRect];
if (self) {
if ([[NSBundle mainBundle] loadNibNamed:nibName
owner:self
topLevelObjects:nil]) {
[self configureView];
}
}
return self;
}
#pragma mark Configure View
- (void)configureView{
[self.view setFrame:[self bounds]];
[self addSubview:self.view];
self.tabOneTextField.stringValue = self.tabOneText;
self.tabTwoTextField.stringValue = self.tabTwoText;
self.tabThreeTextField.stringValue = self.tabThreeText;
}
@end
This works fine in the TabContainerView.xib without issue. Now when I attempt to use this control in two different view controllers, I run into problems. Both of my view controllers are also loaded from Xibs.
In view controller 1 I have something like this:
In view controller 1 I've subclassed the custom view to the TabContainerView subclass which works just fine when I run the application. I've also changed the text to be specific for this view controller. List, Map, Filter are the IBInspectable property values for view controller one. In view controller 2 (not shown), I've done the exact same thing, however different IBInspectable property values specific for view controller 2. However, when I run the application the values never update and always stay as First, Second, and Third. I'm not sure if there is something I'm doing that's causing this problem but any help or tips would be appreciated. (IBDesignable seems to give me a lot of warnings where it breaks and not sure if maybe it's just loading the last saved value for the xib.)