2011-07-25 21 views
0

私はカスタム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]; 
+0

lblCoordsとは何ですか? –

+0

それはUILabelです。 – Echilon

答えて

0

接続lblCords lblCoordsラベルが割り当て解除されたようですtextのセッターを使用しようとしています。このラベルを管理する方法を確認してください。 doubleタイプはオブジェクトタイプではなく、メモリ管理について気にする必要はありません(intなどの他のベースタイプにも当てはまります)。

+0

ラベルはIBで接続されています。私は 'lblCoords.text = @" blah ";を実行するとテキストを設定できます; – Echilon

0

を使用して

+0

これはインターフェースビルダーに接続されており、テキストをプレーンなNSStringに設定できます。 – Echilon

+0

プロパティはラベルを「保持」しますか? –

+0

はい、宣言は '@property(nonatomic、retain)IBOutlet UILabel * lblCoords;'です。問題なくアクセスでき、プリコンパイルされた文字列にテキストを設定できます。 – Echilon

関連する問題