【发布时间】: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