3

これは Craig Schamp の terremoto のコードです。シミュレーター (OS 4.2) では正常に動作しますが、デバイスでは動作しません。

self.currentEarthquake.magnitude = [formatter numberFromString:magString]; and

NSNumber *latituide = [formatter numberFromString:[comp objectAtIndex:0]];

NSNumber *longitude = [formatter numberFromString:[comp objectAtIndex:1]] 

デバイス上ではnullですが、シミュレーターではすべてのデータがあります....ここですべてのコード..私のデバイスは3gで、4.2はNSNumberFormatterの問題です???

if ([elementName isEqualToString:@"title"]) {
  //<title>M 5.8, Banda Sea</title>
  NSArray *components = [self.propertyValue componentsSeparatedByString:@","];
  if (components.count > 1) {
   // strip the M
   NSString *magString = [[[components objectAtIndex:0] componentsSeparatedByString:@" "] objectAtIndex:1];

   NSLog(@"String %@",magString);

   NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
   self.currentEarthquake.magnitude = [formatter numberFromString:magString];
   self.currentEarthquake.place = [components objectAtIndex:1];
   [formatter release];

   NSLog(@"Magnetudine %@",self.currentEarthquake.magnitude);
   NSLog(@"Place %@",self.currentEarthquake.place);

   NSLocale *currentUsersLocale = [NSLocale currentLocale];
   NSLog(@"Current Locale: %@", [currentUsersLocale localeIdentifier]);

  }
 } else if ([elementName isEqualToString:@"updated"]) {
  //<updated>2008-04-29T19:10:01Z</updated>
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
  self.currentEarthquake.lastUpdate = [formatter dateFromString:self.propertyValue];
  [formatter release];

  NSLog(@"Date %@",self.currentEarthquake.lastUpdate);

 } else if ([elementName isEqualToString:@"georss:point"]) {
  NSArray *comp = [self.propertyValue componentsSeparatedByString:@" "];
  NSLog(@"Comp %@",comp);

  NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];


  NSNumber *latituide = [formatter numberFromString:[comp objectAtIndex:0]];
  NSLog(@"Latitude %@",latituide);
  NSNumber *longitude = [formatter numberFromString:[comp objectAtIndex:1]];
  [formatter release];
  CLLocation *location = [[CLLocation alloc] initWithLatitude:latituide.floatValue
                longitude:longitude.floatValue];
  self.currentEarthquake.location = location;
  [location release];

  NSLog(@"Location %@",location);
 } else if([elementName isEqualToString:@"entry"]) {
  [(id)[self delegate] performSelectorOnMainThread:@selector(addEarthquake:)
             withObject:self.currentEarthquake
             waitUntilDone:NO];
 }

2010-12-05 03:46:45.738 Terremoto[251:307] Comp ( "41.9022", "12.4579" ) 2010-12-05 03:46:45.745 Terremoto[251:307] 緯度 (null)

2010-12-05 03:46:45.847 Terremoto[251:307] 場所 <+0.00000000, +0.00000000> +/- 0.00m (速度 -1.00 mps / コース -1.00) @ 05/12/10 03:46:45 GMT-03:00

2010-12-05 03:46:45.854 Terremoto[251:307] 文字列 5.0

2010-12-05 03:46:45.864 Terremoto[251:307] マグネチュージン (null)

2010-12-05 03:46:45.868 Terremoto[251:307] プレイス ホテル エルギフェ

2010-12-05 03:46:45.871 Terremoto[251:307] 現在のロケール: it_IT

2010-12-05 03:46:45.892 Terremoto[251:307] 日付 2010-10-14 14:35:18 +0000

2010-12-05 03:46:45.898 Terremoto[251:307] Comp (「-6.1020」、「127.5017」)

デバイスログ

4

2 に答える 2

6

それが機能しない理由は、おそらくあなたのロケール (イタリア語) ではピリオド "." です。は有効な小数点記号ではありません。

呼び出し-[NSNumberFormatter setDecimalSeparator:]て正しい値に設定します。

于 2010-12-05T09:14:38.887 に答える
1

同じコンテキスト(座標の解析)で同じ問題がありました。私はiOS 4.3を使用しています。私が使用した Mac と iPad はどちらもドイツ語に設定されているため、IMO フォーマッターは同じように動作するはずですが、そうではありませんでした。

私はこれを使用することになりました:

 pi.latitude = [NSNumber numberWithDouble:[(NSString *)[coords objectAtIndex:0] doubleValue]];

これは、シミュレーターとデバイスで機能します。

于 2011-04-18T21:04:40.327 に答える