功能未声明错误

时间:2011-11-05 14:22:36

标签: objective-c xcode function

你能发现错误吗?为什么编译器认为我的函数未声明?谢谢。 -Rob

在.h文件中

-(int) getW:(int)xPosition;

在.m文件中

-(int) getW:(int)xPosition {
    return (xPosition-58)/48; 
}

在另一个程序中,调用函数:

whichTile=[getW: xPosition] ;   <----ERROR getW undeclared (first use in this function)

(xPosition和whichTile已声明为整数,并在程序的早期使用)。我也尝试了(NSInteger)(以及其他一百万个排列!)。谢谢你的帮助。-Rob

1 个答案:

答案 0 :(得分:1)

您已声明了一个实例方法,并在未指定实例的情况下调用它。

例如:

whichTile = [self getW:xPosition];
-or-
whichTile = [anObject getW:xPosition];

与其他语言不同,self在发送消息时并不隐含。

相关问题