【问题标题】:How to call a method from another method with arguments如何使用参数从另一个方法调用方法
【发布时间】:2011-09-20 12:09:03
【问题描述】:

我想从 updateButtonPressed 方法中调用另一个方法。 这是我尝试过的:

-(IBAction) updateButtonPressed{
    [self loadScrollViewWithPage];
} 

但问题是 loadScrollViewWithPage 方法有参数。那个方法是这样的:

- (void)loadScrollViewWithPage:(int)page {
 }

如何调用这个方法?

【问题讨论】:

    标签: iphone objective-c ios ios4


    【解决方案1】:

    如果我理解正确,您想知道如何将参数与消息一起传递给对象,对吗?试试:

    -(IBAction) updateButtonPressed{
        int foo = 4;
        [self loadScrollViewWithPage:foo]; // a colon, followed by the argument
    } 
    

    不过,我建议您大致了解一下 Objective-C 语言。

    http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/introduction/introobjectivec.html

    【讨论】:

      【解决方案2】:
      - (IBAction) updateButtonPressed{
         int tempValue=5;
         [self loadScrollViewWithPage:tempValue];
      }
      

      【讨论】:

        猜你喜欢
        • 2011-06-18
        • 2018-09-03
        • 2015-06-16
        • 1970-01-01
        • 2010-12-24
        • 1970-01-01
        • 2017-04-27
        • 2015-08-14
        • 2022-01-22
        相关资源
        最近更新 更多