Objective c 将参数传递给方法的问题

Objective c 将参数传递给方法的问题,objective-c,xcode,cocos2d-iphone,Objective C,Xcode,Cocos2d Iphone,我试图用float参数调用一个方法,但该方法得到的值不是我发送的值 下面是调用的代码(实际调用是最后一行的最后一部分,[child setFaceDirection:direcao];): 以下是该方法的代码: -(void) setFaceDirection: (float) angle { NSLog(@"Value Recieved: %f", angle); [theSprite setRotation: - angle ]; } 下面是浮点变量direcao的声明 @

我试图用float参数调用一个方法,但该方法得到的值不是我发送的值

下面是调用的代码(实际调用是最后一行的最后一部分,[child setFaceDirection:direcao];):

以下是该方法的代码:

-(void) setFaceDirection: (float) angle {
    NSLog(@"Value Recieved: %f", angle);
    [theSprite setRotation: - angle ];
}
下面是浮点变量direcao的声明

@interface PersControlNode : CCNode <CCTargetedTouchDelegate> {
            // ...
        float direcao;
           // ...

}
//  ...
@end
我做错了什么?我不熟悉目标C。感谢所有试图帮助我的人


如果我使用int而不是float,效果会更好,但是即使这样,仍然有一些错误。

我相信这与编译器的自动类型转换有关,但是对C更了解的人必须对此进行解释。要解决此问题,请将
angle
参数的类型更改为
double

是否有其他名为
setFaceDirection:
的方法采用不同的类型


是否没有编译器警告?

我在将浮点值传递给仅在*.m文件中实现但未在*.h文件中声明的方法时遇到了相同的问题

例如:

如果您正在使用调用该方法:

  • (void)updateScreen:(float)值; { ... }
确保它在该类的相应接口文件中声明。并确保您没有以下警告: “对象可能不响应-(void)updatedScreen…”

我声明了接口文件中不起作用的任何函数,它工作得很好

我也有同样的问题。 在头文件(.h)中,参数为int。 但是在实现文件(.m)中,参数是float或double

@interface ...
{}
- (void) resizeImage:(UIImage *)imageToResize ToFitWidth:(int)max_width andHeight:(int)max_height;


@implementation ...
- (void) resizeImage:(UIImage *)imageToResize ToFitWidth:(float)max_width andHeight:(float)max_height {
    NSLog(@"max_width: %f", max_width);
    ...
值始终为0.000000000

解决办法可以是:
因此,可能是您没有在头(.h)中声明该方法,或者您只是忘记更改头(.h)中参数的类型,因此该方法的实现使用头的参数类型

如果参数的类型为int,效果会更好。但即使如此,它也不是perfectHi。。我有其他的方法叫做setFaceDirection,但它们也采用浮动。我得到的唯一警告是“CCNode可能不会响应setFaceDirection”,这是真的,这就是为什么我检查它是否先响应的原因。但是现在我把所有的都转换成int,警告消失了…只是澄清一下:我有一些类使用setFaceDirection:(float)angle{..}。他们都乘了浮子。然后,由于这个问题,我将所有内容都更改为int,并且它(有点)正常工作。但我必须能够将浮动作为参数传递。有趣的是,当所有内容都是int时,警告就消失了。直到现在我才注意到这一点。谢谢你,伙计。
Value Sent:       -16.699266
Value Recieved: 0.000000
Value Sent:       -16.699301
Value Recieved: 36893488147419103232.000000
Value Sent:       -16.699625
Value Recieved: -0.000000
Value Sent:       48.366463
Value Recieved: 2.000000
Value Sent:       48.366451
Value Recieved: -36893488147419103232.000000
Value Sent:       48.366428
Value Recieved: 0.000000
Value Sent:       48.366444
Value Recieved: -0.000000
Value Sent:       14.036244
Value Recieved: -0.000000
Value Sent:       14.036238
Value Recieved: -2.000000
Value Sent:       14.036201
Value Recieved: -36893488147419103232.000000
Value Sent:       14.036191
Value Recieved: -0.000000
Value Sent:       14.036273
Value Recieved: 36893488147419103232.000000
Value Sent:       12.528809
Value Recieved: 0.000000
Value Sent:       12.528766
Value Recieved: 36893488147419103232.000000
Value Sent:       12.528852
Value Recieved: -2.000000
Value Sent:       12.528863
Value Recieved: 0.000000
Value Sent:       -101.309929
Value Recieved: -36893488147419103232.000000
Value Sent:       -101.309860
Value Recieved: -2.000000
@interface ...
{}
- (void) resizeImage:(UIImage *)imageToResize ToFitWidth:(int)max_width andHeight:(int)max_height;


@implementation ...
- (void) resizeImage:(UIImage *)imageToResize ToFitWidth:(float)max_width andHeight:(float)max_height {
    NSLog(@"max_width: %f", max_width);
    ...