【问题标题】:Loading an XIB having nil IBOutlets Properties加载具有 nil IBOutlets 属性的 XIB
【发布时间】:2016-05-06 23:42:36
【问题描述】:

请参考以下代码。其中我有一个属性

@property (nonatomic,strong) CustomView *promptView;

getter 方法正在使用 XIB 加载它。

- (CustomView *)promptView
    {
        if (!_promptView) {
            _promptView = [[[NSBundle mainBundle] loadNibNamed:@"CustomViewXIB" owner:self options:nil]  objectAtIndex:0];
            [_promptView.buttonCheckMark addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            _promptView.alertMessage.text = @"hello text";
            _promptView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        }

        return _promptView;
    }

但我的 alertMessage 值为零

这是一个 IBOutlet,声明并连接到 CustomView.h

@property (weak, nonatomic) IBOutlet UILabel *alertMessage;

还尝试将文件所有者设置为 CustomView。我完美地获得了 UIView 对象(promptView),但属性为零。 如何解决?

尝试了以下解决方案

【问题讨论】:

  • 按钮事件正在工作。我可以设置按钮目标和选择器,但 alertMessage 属性为零。
  • 你有没有把CustomViewXIB中View的File Owner类改成CustomView
  • 是的,我也试过了
  • 请检查我的答案我认为未设置视图类。
  • 尝试清除项目并重新启动xcode,它发生在我身上一次,问题是xcode本身。

标签: ios objective-c xib iboutlet


【解决方案1】:

请查看截图

你这样做了吗?

【讨论】:

  • 请参考我上传的图片
猜你喜欢
  • 2019-04-20
  • 1970-01-01
  • 2017-01-08
  • 2019-09-02
  • 2012-10-13
  • 2021-01-15
  • 1970-01-01
  • 1970-01-01
  • 2019-09-16
相关资源
最近更新 更多