我使用IBInspectable属性遇到了一个小的并发症,并且不确定它是否与我的xib和xib使用有关。我试图在多个视图控制器之间重用自定义控件。该控件是一个自定义选项卡管理器:
IBInspectable Attributes在此xib中配置为:First,Second,Third。
以下是头文件的相应代码。
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
这在TabContainerView.xib中没有问题。现在,当我尝试在两个不同的视图控制器中使用此控件时,我遇到了问题。我的两个视图控制器也都是从Xibs加载的。
在视图控制器1中我有这样的东西:
在视图控制器1中,我将自定义视图子类化为TabContainerView子类,它在运行应用程序时工作得很好。我还将文本更改为特定于此视图控制器。 List,Map,Filter是视图控制器1的IBInspectable属性值。在视图控制器2(未示出)中,我做了完全相同的事情,但是特定于视图控制器2的不同IBInspectable属性值。但是,当我运行应用程序时,值永远不会更新并始终保持为First,Second,和第三。我不确定是否有什么东西导致了这个问题,但是我会感激任何帮助或提示。 (IBDesignable似乎给了我很多警告,它会中断并且不确定它是否只是加载最后保存的xib值。)
答案 0 :(得分:0)
您是否在控制器2 .h文件中导入了#import“TabContainerView.h”。