0

lat\lon を他のインスタンスに渡そうとしています。私は lat\lon の欺瞞への呼び出しを追加し、それらを保存しましたNSString

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    lat = newLocation.coordinate.latitude;
    lon = newLocation.coordinate.longitude;
    latValueNSString = [NSString stringWithFormat: @"%f", lat];
    lanValueNSString = [NSString stringWithFormat: @"%f", lan];

}

lat,lonフロートタイプです。

このインターフェイスにアクセスするとき

AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;

デバッガー モードでは、lat、lon (float) の値が表示されますが、取得できません。にアクセスするlatValueNSString/lanValueNSString と、「freed object」が表示されます

これらの値を渡すにはどうすればよいですか? 私の間違いはどこですか?NSSunmber同じ問題で同じことを試しました

4

2 に答える 2

0

オブジェクトを割り当てているautoreleased(オブジェクト[NSString stringWithFormat: @"%f", lat]を返すutoreleased)ので、そのエラーが発生します。さらに使用するために値を保持する必要があります。

次のようにメソッドを変更するだけです。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    lat = newLocation.coordinate.latitude;
    lon = newLocation.coordinate.longitude;
    self.latValueNSString = [NSString stringWithFormat: @"%f", lat];
    self.lanValueNSString = [NSString stringWithFormat: @"%f", lan];

}

また

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    lat = newLocation.coordinate.latitude;
    lon = newLocation.coordinate.longitude;
    latValueNSString = [[NSString stringWithFormat: @"%f", lat] retain];
    lanValueNSString = [[NSString stringWithFormat: @"%f", lan] retain];

}
于 2012-10-04T17:58:57.680 に答える
-1

float変数のプロパティを使用assignし、解放する必要はありません。NSString変数についてretain/releaseは、問題ありません。

于 2012-09-07T10:08:09.873 に答える