2010-07-30 5 views
0

Pour certains ou toute autre raison quand je l'appelle la méthode d'initialisation et d'essayer de régler la propriété il semble ne jamais travailler:Définition d'une propriété NSNumber hors de portée

//This is where I am setting the value 
Hotel *newHotel = [[Hotel alloc]initWithCoordinate: coordinate 
        hotelId:[NSNumber numberWithInt:1234]]; 


//This is the implementation of the method I am calling 
- (id)initWithCoordinate:(CLLocationCoordinate2D)c hotelId:(NSNumber *)hId 
{ 
    self = [super init]; 
    coordinate = c; 

    hotelId = hId; //When I access this property afterwards its always out of scope 

    return self; 
} 

//This is the interface 
@interface Hotel : NSObject <MKAnnotation> 
{ 
    NSNumber *hotelId; 
} 

@property (nonatomic, retain) NSNumber *hotelId; 

- (id)initWithCoordinate:(CLLocationCoordinate2D)c hotelId:(NSNumber *)hotelId; 

@end 

Répondre

0

j'ai changé le type de NSString en désespoir de cause et que travaillé. Veuillez voter pour fermer si vous le souhaitez, mais aucune des suggestions n'a fonctionné.

1

Utilisation:

self.hotelId = hId; 

si que vous utilisez le setter de la propriété.

0

Vos descriptions de méthode dans votre interface et dans l'implémentation ne correspondent pas.

+0

Ils n'ont pas besoin aussi parce que la méthode est toujours appelée – TheLearner

1

utilisation

self.hotelId 

au lieu de hotelId ... peut-être il montre juste hors de portée ... mais la valeur a affecté correctement

Questions connexes