将NSNumber属性设置为超出范围

时间:2010-07-30 11:02:38

标签: iphone objective-c

由于某些或其他原因,当我调用init方法并尝试设置属性时,它似乎永远不会起作用:

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

4 个答案:

答案 0 :(得分:1)

使用:

self.hotelId = hId;

以便您使用该属性的setter。

答案 1 :(得分:1)

使用

self.hotelId 

而不是hotelId ...可能只是显示超出范围...但值已正确分配

答案 2 :(得分:0)

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

答案 3 :(得分:0)

我在绝望中将类型更改为NSString并且有效。如果你认为合适,请投票结束,但没有任何建议有效。

相关问题