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
You can load the nib like this:
This will return the first occurence of a GameResultsView.