obj-c:iphone编程,带2个参数的调用方法

时间:2010-06-19 21:56:05

标签: objective-c methods parameters

我有一个方法,将另一个带有1个参数的方法调用到另一个类。它工作得很好,但现在我还需要一个参数,这是我的代码:

我正在收到'addobject may not response'

test.m

调用方法:

DrunkeNewIdeaAppDelegate *appDelegate = (DrunkeNewIdeaAppDelegate *)[[UIApplication sharedApplication] delegate];
  Testes *myLevelObject = (Testes *)appDelegate.testViewController1;
  [myLevelObject addobject:rephereanswer,nbimportant];

方法叫做:

testes.h

-(void)addobject:(double)rephereanswer:(double)nbimportant;

testes.m

-(void)addobject:(double)rephereanswer:(double)nbimportant{

2 个答案:

答案 0 :(得分:2)

试试这个

[myLevelObject addobject:rephereanswer :nbimportant];

答案 1 :(得分:1)

您的方法的签名实际上是addObject: :。参数前面有冒号,所以你可以这样调用你的方法:

[myLevelObject addobject:rephereanswer :nbimportant];

但是,在Objective-C中,流行的风格是命名所有参数,因此您可能希望将方法更改为:

- (void)addobject:(double)rephereanswer otherParam:(double)nbimportant;

在这种情况下,您可以这样称呼它:

[myLevelObject addobject:rephereanswer otherParam:nbimportant];

(比otherParam更具描述性的名称也是可取的。)