【问题标题】:obj-c : iphone programming, call method with 2 parametersobj-c : iphone编程,2个参数调用方法
【发布时间】:2011-03-05 21:04:26
【问题描述】:

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

我收到“添加对象可能没有响应”

test.m

调用方法:

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

方法调用:

睾丸.h

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

睾丸.m

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

【问题讨论】:

    标签: objective-c methods parameters


    【解决方案1】:

    试试这个

    [myLevelObject addobject:rephereanswer :nbimportant];
    

    【讨论】:

      【解决方案2】:

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

      [myLevelObject addobject:rephereanswer :nbimportant];
      

      然而,在 Objective-C 中,流行的风格是命名所有你的参数,所以你可能想把你的方法改成这样:

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

      在这种情况下,你会这样称呼它:

      [myLevelObject addobject:rephereanswer otherParam:nbimportant];
      

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

      【讨论】:

        猜你喜欢
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多