2

我想从一个实例方法调用一个类方法来使用它的返回值。

这是我的课堂方法

+(double) minFMFrequency {

    return 88.3;
}

这是我的实例方法

-(void) chackFrequency {

    switch (band) {
        case 'F':
            if (self.frequency > Value obtained from class method )
                frequency=107.9;
            break;

        default:
            break;
    }

}

band并且frequency是实例变量。

4

2 回答 2

13
+(void)classMethod
{
    [self anotherClassMethod]; // in a class method, self refers to the class
}

-(void)instanceMethod
{
    [self anotherInstanceMethod]; //in an instance method self refers to the object, or instance 

    [[self class] classMethod]; //to call a class method from an instance send the instance the class message

}

所以在你的情况下:[[self class] minFMFrequency];

于 2012-04-07T19:40:55.157 回答
0

欺骗。检查这个

你需要做:[[self class] ClassProperties]

所以......对你来说:chackFrequency你可以打电话给[[self class] minFMFrequency].

于 2012-04-07T19:40:43.730 回答