1

私はこれが以前に尋ねられたことを知っていますが、私は以前の質問のいくつかを経験しました、そして私はそれらを私の問題に関連付けることができません。

実行するすべての計算を処理するクラスをアプリケーションで開発しようとしていますが、double値を返そうとするより単純なメソッド呼び出しの1つに問題があります。私はiOSコーディングにかなり慣れていないので、間違っているのはおそらく単純なことです。とにかくここにコードがあります

PS十分な情報を提供したかどうかわからないので、何か追加する必要がある場合はお知らせください

メソッド呼び出しを行う.mファイルから

- (void)locationManager:(CLLocationManager *)manager 
        didUpdateToLocation:(CLLocation *)newLocation 
        fromLocation:(CLLocation *)oldLocation
{
    // print the location to the device logs to aid in debugging
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    //this is the problem line here
    //Problem solved thans to trojanfoe and H2CO3
    double currentSpeed = [[BIDCalculations calculateSpeed: newLocation] doubleValue];

    //the problem line was replace with this new line which solved the error
    double currentSpeed = [BIDCalculations calculateSpeed: newLocation];


    // if there is a location to report, print it to the screen
    if (currentLocation != nil) {
        _positionLabel.text = [NSString stringWithFormat:@"%.3f, %.3f",
                               currentLocation.coordinate.longitude,
                               currentLocation.coordinate.latitude];

    }
}

メソッドが配置されている.mファイルから(計算クラス)

@implementation BIDCalculations

+ (double)calculateSpeed:(CLLocation *)newLocation;
{
    return newLocation.speed;
}

計算クラスの.hファイルから

@interface BIDCalculations : NSObject

+ (double)calculateSpeed:(CLLocation *)newLocation;

@end
4

2 に答える 2

4

メソッドはすでに を返しているdoubleため、問題の行を次のように変更します。

double currentSpeed = [BIDCalculations calculateSpeed:newLocation];
于 2013-03-01T14:28:16.893 に答える
0
+ (double)calculateSpeed:(CLLocation *)newLocation

そのメソッドはすでに を返しますdouble

double currentSpeed = [BIDCalculations calculateSpeed:newLocation];

で十分です。

于 2013-03-01T14:28:27.223 に答える