私はカスタムDTOオブジェクトに緯度/経度を含むXMLドキュメントを解析しています。ダブル値からラベルを設定しようとすると、エラーが発生しますが、コンソールにログオンすると動作します。私はこれが記憶問題であると確信しています。私はこのコードを持っている:倍精度 - 割り当て、保持、読み込み?
NSString *postCode =[[eleData nodeForXPath:@"Location/PostCode" error:nil] stringValue];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setGeneratesDecimalNumbers:TRUE];
NSString *rawLat =[ [eleData nodeForXPath:@"Location/Latitude" error:nil] stringValue];
double lat = [rawLat doubleValue];
NSString *rawLng = [[eleData nodeForXPath:@"Location/Longitude" error:nil] stringValue];
double lng = [rawLng doubleValue];
[info initWithLocation:prettyLocation latitudeIs:lat longitudeIs:lng withPostCode:postCode];
NSLog([NSString stringWithFormat:@"%f", lat]); // works
NSLog(info.location.postCode); // works
NSLog([NSString stringWithFormat:@"%f", info.location.latitude]); // works
をデータを表示するには:
@interface LocationResult : NSObject {
LoginResultType result;
LocationInfo *location;
}
@property (nonatomic, readwrite) LoginResultType result;
@property (nonatomic, retain) LocationInfo *location;
@end
@interface LocationInfo : NSObject {
LatLng *location;
NSString *niceLocation;
}
@property (nonatomic, retain) LatLng *location;
@property (nonatomic, retain) NSString *niceLocation;
-(LocationInfo *)initWithLocation:(NSString *)strNiceLocation latitudeIs:(double)latitude longitudeIs:(double)lonitude withPostCode:(NSString *)postCode;
@end
@interface LatLng : NSObject {
NSString *postCode;
double latitude;
double longitude;
}
@property (nonatomic, retain) NSString *postCode;
@property (nonatomic, readwrite) double latitude;
@property (nonatomic, readwrite) double longitude;
-(LatLng*)initWithLocation:(NSString *)strPostCode latitudeIs:(double)latitude longitudeIs:(double)longitude;
@end
オブジェクトを初期化するために、私はTouchXMLを使用してXMLドキュメントから解析しています
lblCurrentPostcode.text = result.location.location.postCode;
NSLog([NSString stringWithFormat:@"%d, %d", result.location.location.latitude, result.location.location.longitude]); // this works
lblCoords.text = [NSString stringWithFormat:@"%@, %@", result.location.location.latitude, result.location.location.longitude]; // message sent to deallocated instance exception, crashes app
lblCoords.text = [NSString stringWithFormat:@"%f, %f", result.location.location.latitude, result.location.location.longitude]; // message sent to deallocated instance exception, crashes app
私はドン」私がコンソールにログオンしてPostCode(NSString *)のテキストを設定できる理由を理解していますが、座標のテキストは設定しません。割り当て解除インスタンス例外
中に送ら
メッセージを:メッセージは述べてインタフェースビルダまたは
lblCoords = [[UILabel alloc] init]; lblCoords.text = [NSString stringWithFormat:@"%@, %@", result.location.location.latitude, result.location.location.longitude]; lblCoords.text = [NSString stringWithFormat:@"%f, %f", result.location.location.latitude, result.location.location.longitude];
lblCoordsとは何ですか? –
それはUILabelです。 – Echilon