我有一个类(class)(生成核心数据):
@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
为其添加一个类别:
@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];
}
它似乎永远不会到达 setLattitudeAndLogitudeByCooperative 方法内的那些断点, 调试显示它甚至没有调用它们!为什么?
最佳答案
someMethod
是否已达到?检查是否在其头部使用断点或额外的 NSLog
。
如果不是,那么您的问题出在其他地方,因为您的程序流程与您预期的不同。
如果达到了,那么self.place
显然是nil
。这意味着您从未初始化过它,并且您的程序流程与您想象的不同。
关于objective-c - 类别实例方法不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10213786/