Ios Objective-C中的调用方法层次结构

Ios Objective-C中的调用方法层次结构,ios,objective-c,scope,Ios,Objective C,Scope,我声明一个类方法: +(int)widthScaled:(UIImage *)image maximumHeight:(int)max{ int width = 0; width = (image.size.width - (((image.size.height - max)*100)/image.size.height)*image.size.width)/100; return width; } 在同一个类中,我声明了如下实例方法: - (void)gener

我声明一个类方法:

+(int)widthScaled:(UIImage *)image maximumHeight:(int)max{
    int width = 0;
    width = (image.size.width - (((image.size.height - max)*100)/image.size.height)*image.size.width)/100;

    return width;

}
在同一个类中,我声明了如下实例方法:

- (void)generarVistas{
    if(...){
       ...
    }else{
         for(...){
               ...
//I need to put the class method here but if I call the class method like this, don't recognize
               int variable = [[self class] widthScaled:image maximumHeight:max];
...
}
}
我尝试将类方法放在实例方法中,但不起作用。
我应该指出什么上下文来识别类方法?

您面临的问题是,
[self class]
是一个运行时调用,它的返回结果在运行时之前是未知的。编译器不知道它是什么类。您正在编写的代码必须始终从固定类调用,因此不要这样做。如果类是FooClass,则使用以下表单:

int variable = [FooClass widthScaled:image maximumHeight:max];

(将
[self class]
替换为您的类名,例如
FooClass

在NSObject、UIViewController、AppDelegate、,UIView…?创建类的静态变量,在
-viewdiload
-init
方法中分配它,然后使用此变量调用实例方法,但它都在同一个类中。我测试您的实现在我这方面的工作。您能否详细说明调用该类方法时显示的警告/错误?如果您的问题已解决,请接受对您有帮助的答案,或者添加一个答案,如果有其他帮助,请不要将您的问题解决。我已经删除了这个。好的,我解决了重写代码的问题,因为可能一些括号是错误的。我之所以调用[self class],是因为我需要调用的方法位于我调用该方法的同一个类中。现在,正确完成这项工作:widthImage=[[self class]widthScaled:imageProduct maximumHeight:maxHeight];不,不要使用“[自我类]”。如我在回答中所说,请使用您的班级名称。