0
編譯器因爲擁有未聲明的標識符而被標記,並想知道什麼是解決此問題的最佳方法?在目標文件中使用未聲明的標識符
這是我第一次使用plist來存儲數據,所以我不確定最好的方法是什麼。謝謝。
有評論出錯誤消息:
Destination.h
#import "Destination.h"
@implementation Destination
@synthesize coordinate = _coordinate;
@synthesize title = _title;
@synthesize subtitle = _subtitle;
@synthesize destinationName = _destinationName;
@synthesize destinationImage = _destinationImage;
-(id)initWithDestinationIndex:(NSUInteger)destinationIndex {
if (self = [super init]) {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Destinations" ofType:@"plist"];
NSDictionary *destinations = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSArray *destinationsArray = [destinations objectForKey:@"DestinationData"];
NSDictionary *data = [destinationsArray objectAtIndex:destinationIndex];
self.destinationImage = [UIImage imageNamed:[data objectForKey:@"DestinationImage"]];
self.destinationName = [data objectForKey:@"DestinationName"];
NSDictionary* destinationLocation = [data objectForKey:@"DestinationLocation"];
destinationCoordinate.latitude = [[destinationLocation objectForKey:@"Latitude"]doubleValue];// Use of undeclared identifier 'destinationCoordinate'
destinationCoordinate.longitude = [[destinationLocation objectForKey:@"Longitude"]doubleValue];// Use of undeclared identifier 'destinationCoordinate'
self.coordinate = destinationCoordinate;//Use of undeclared identifier 'destinationCoordinate'
self.title = [destinationLocation objectForKey:@"Title"];
self.subtitle = [destinationLocation objectForKey:@"Subtitle"];
}
return self;
}
-(UIImage *)destinationImage {
return destination.destinationImage;//Use of undeclared identifier 'destination'; did you mean 'Destination'?
}
-(NSString *)destinationName {
return destinationName;//Use of undeclared identifer 'destinationName'; did you mean '_destinationName'?
}
-(CLLocationCoordinate2D)destinationCoordinate {
return destination.coordinate;//Use of undeclared 'destination'; did you mean 'Destination'
}
@end
Destination.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Destination : NSObject<MKAnnotation>
@property(nonatomic,readwrite)CLLocationCoordinate2D coordinate;
@property(nonatomic,readwrite,copy)NSString *title;
@property(nonatomic,readwrite,copy)NSString *subtitle;
@property(nonatomic,strong)NSString *destinationName;
@property(nonatomic,strong)UIImage *destinationImage;
-(id)initWithDestinationIndex:(NSUInteger)destinationIndex;
@end
謝謝。已經這樣做了,但我仍然在爲其他變量(destinationCoordinate和其他變量)獲取相同的錯誤。它們是否應該被聲明爲局部變量? – pdenlinger 2012-04-19 16:09:53
@pdenlinger那麼,如果他們是同樣的問題,那麼相同的解決方案將工作,我猜。 – trojanfoe 2012-04-19 19:14:47