2012-04-18 72 views
0

我有一个类(核心数据生成):分类实例方法不调用

@interface Place : NSManagedObject 

@property (nonatomic, retain) NSString * title; 
@property (nonatomic, retain) NSString * subtitle; 
@property (nonatomic, retain) NSNumber * latitude; 
@property (nonatomic, retain) NSNumber * longitude; 

@end 
@implementation Place 

@dynamic title; 
@dynamic subtitle; 
@dynamic latitude; 
@dynamic longitude; 

@end 

ADN它的类别:

@interface Place (Create) 
+ (Place *)placeWithTitle:(NSString *)title 
     inManagedObjectContext:(NSManagedObjectContext *)context; 

+(Place *) placeWithTitle:(NSString *)title andSubtitle:(NSString *)subtitle inManagedObjectContext:(NSManagedObjectContext *)context; 
+(Place *) placeWithCoordinate:(CLLocationCoordinate2D) coordinate inManagedObjectContext:(NSManagedObjectContext *)context; 
- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate; 


- (CLLocationCoordinate2D) coordinate; 
@end 

在这个类别中有实例方法:

- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate 
{ 
    self.latitude=[NSNumber numberWithDouble:coordinate.latitude];//break point HERE 
    self.longitude=[NSNumber numberWithDouble:coordinate.longitude]; 
} 

-(CLLocationCoordinate2D) coordinate 
{ 
    CLLocationCoordinate2D coord;//break point HERE 
    coord.latitude=[self.latitude doubleValue]; 
    coord.longitude=[self.longitude doubleValue]; 
    return coord; 
} 

正如你所看到的我必须在那里断点。现在,然后我调用这些方法

#import "Place+Create.h" 

-(void)someMethod 
{ 
    [self.place setLattitudeAndLongitudeByCoordinate:coordiante]; 
} 

它似乎从来没有达到法setLattitudeAndLogitudeByCoordinate内的断点, 和调试表明,它甚至不给他们打电话!为什么?

+0

'someMethod'是否到达过?如果不是,那么你的问题就在别的地方。如果达到了,那么'self.place'显然是'nil'。 – Till 2012-04-18 16:30:30

+0

没错,解决它。谢谢! – 2012-04-18 16:56:55

+0

我在答复中重复了这一点,以防止此问题未得到答复。 – Till 2012-04-18 17:33:32

回答

1

someMethod有史以来?检查是否使用断点或额外的NSLog

如果不是,那么你的问题在别的地方,因为你的程序流程与你预期的不同。

如果达到了,那么self.place显然是nil。这意味着你从来没有初始化过它,你的程序流程与你想象的不同。

相关问题