2010-07-30 25 views
0

出于某种或其他原因,当我调用init方法,并尝试将它似乎永远不会工作性质:设置一个NSNumber财产超出范围

//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 

回答

0

我在绝望和改变类型的NSString工作。如果您觉得合适,请投票结束,但没有任何建议可行。

1

用途:

self.hotelId = hId; 

所以你使用财产的设置者。

0

您的界面和实现中的方法描述不匹配。

+0

他们不需要,因为方法仍然被调用 – TheLearner 2010-07-30 11:24:54

1

使用

self.hotelId 

代替hotelId ...可能是它只是显示出的范围......但价值已经正确分配