加载具有nil IBOutlets属性的XIB

时间:2016-01-29 09:35:31

标签: ios objective-c xib iboutlet

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

@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),但属性是零。 如何解决这个问题?

  

尝试以下解决方案

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

请检查屏幕截图 enter image description here

你做到了吗?

相关问题