使用 NIB 文件创建 UIView 实例时链接 IBOutlet
我使用 NIB 文件的内容创建了一个 UIView 对象,如下所示:
self.results = [[[NSBundle mainBundle] loadNibNamed:@"ResultsView" owner:self options:nil] lastObject];
self.results.frame = CGRectMake(0, 0, 320, 500);
但是 self.results 实际上是 UIView 的子类:
@interface GameResultsView : UIView {
UILabel *title;
}
@property (nonatomic, retain) IBOutlet UILabel *title;
@end
我有通过 Interface Builder 将 GameResults
中定义的 title
属性与 UILabel
对象连接起来。但在执行过程中,当视图分配给 self.results 时,应用程序会停止并显示 SIGABRT
消息:
-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4c2f780
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4c2f780'
看起来标签根本无法连接。这样做的正确方法是什么(如果有)?我的目的是将此自定义视图添加到 UIScrollView
对象中。
谢谢!
更新:我正在使用 Xcode 4
I have created a UIView
object using the contents of a NIB file like this:
self.results = [[[NSBundle mainBundle] loadNibNamed:@"ResultsView" owner:self options:nil] lastObject];
self.results.frame = CGRectMake(0, 0, 320, 500);
But self.results
is a subclass of UIView
actually:
@interface GameResultsView : UIView {
UILabel *title;
}
@property (nonatomic, retain) IBOutlet UILabel *title;
@end
I have connected the title
attribute defined in GameResults
with a UILabel
object through Interface Builder. But during execution the application stops with a SIGABRT
message when the view is assigned to self.results
:
-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4c2f780
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4c2f780'
It seems like the label cannot be connected at all. What's the right way of doing this (if any)? My purpose here is add this custom view to a UIScrollView
object.
Thanks!
UPDATE: I'm using Xcode 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样加载笔尖:
这将返回第一次出现的 GameResultsView。
You can load the nib like this:
This will return the first occurence of a GameResultsView.