0

UIView使用这样的 NIB 文件的内容创建了一个对象:

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 Buildertitle将定义的属性GameResults与对象连接起来。UILabel但是在执行过程中,SIGABRT当视图被分配给时,应用程序会停止并显示一条消息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'

似乎标签根本无法连接。这样做的正确方法是什么(如果有的话)?我的目的是将此自定义视图添加到UIScrollView对象中。

谢谢!

更新:我正在使用 Xcode 4

4

1 回答 1

1

您可以像这样加载笔尖:

UINib * nib = [UINib nibWithNibName:aName bundle:nil];

NSArray * nibContent = [nib instantiateWithOwner:self options:nil];

for (id aView in nibContent) {
    if ([aView isKindOfClass:[GameResultsView class]]) {
         return aView;
    }
}

这将返回第一次出现的 GameResultsView。

于 2011-05-23T06:47:23.447 回答