【问题标题】:IBInspectable property values not updating in xibIBInspectable 属性值未在 xib 中更新
【发布时间】:2016-03-18 02:28:57
【问题描述】:

我在使用 IBInspectable 属性时遇到了一个小问题,但不确定它是否与我的 xib 和 xib 使用有关。我正在尝试在多个视图控制器之间重用自定义控件。该控件是一个自定义选项卡管理器:

IBInspectable 属性在此 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 是视图控制器一的 IBInspectable 属性值。在视图控制器 2(未显示)中,我做了完全相同的事情,但是视图控制器 2 特定的不同 IBInspectable 属性值。但是,当我运行应用程序时,这些值永远不会更新,并且始终保持为 First、Second 和 Third .我不确定我正在做的事情是否会导致此问题,但我们将不胜感激任何帮助或提示。 (IBDesignable 似乎在它中断的地方给了我很多警告,并且不确定它是否只是为 xib 加载最后保存的值。)

【问题讨论】:

  • 如果视图控制器 1 能工作而视图控制器 2 不能工作,你必须找出不同之处。
  • 两个视图控制器都会收到很多警告吗?

标签: objective-c cocoa nsview ibdesignable ibinspectable


【解决方案1】:

您是否在控制器 2 .h 文件中导入了 #import "TabContainerView.h"。

【讨论】:

  • 是的,我试过了,但控制选项卡最终仍然显示第一、第二和第三。
猜你喜欢
  • 2019-04-27
  • 2017-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多