Je développe une application iOS avec le dernier SDK et XCode 4.2. Je veux utiliser un XIB personnalisé dans un UIView personnalisé.UIView personnalisé avec XIB personnalisé: IBOutlets ne fonctionne pas
Mon UIView personnalisé:
@interface CoordinateView : UIView {
/**
*/
ARGeoCoordinate *geoCoordinate;
/**
*/
IBOutlet UILabel* title;
/**
*/
IBOutlet UILabel* subTitle;
/**
*/
IBOutlet UIImageView* image;
}
Mise en œuvre:
@implementation CoordinateView
@synthesize geoCoordinate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code.
//
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CoordinateView" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CoordinateView class]])
{
[self addSubview:currentObject];
break;
}
}
}
return self;
}
- (id)initForCoordinate:(ARGeoCoordinate *)coordinate
{
self.geoCoordinate = coordinate;
CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT);
self = [self initWithFrame:theFrame];
if (self)
{
title.text = geoCoordinate.title;
image.image = [UIImage imageNamed:[NSString stringWithFormat:@"03%d.jpg", geoCoordinate.id]];
}
return self;
}
Pour initialiser CoordinateView
j'utiliser la méthode initWithCoordinate
.
Debugging J'ai trouvé que title
est nul ici à l'intérieur initWithCoordinate
:
title.text = geoCoordinate.title;
Je l'ai utilisé Interface Builder pour IBOutlets 'lien'.
Qu'est-ce que je fais mal?
Le problème existe toujours avec XCode 9 et iOS 11, mais pas la boîte de dialogue à l'étape 3. Pourriez-vous s'il vous plaît mettre à jour votre réponse? – iOSdev