如何使用参数从另一个方法调用方法

时间:2023-01-24 11:05:18

I want to call another method from updateButtonPressed method. this is how I tried.

我想从updateButtonPressed方法调用另一个方法。这就是我尝试的方式。

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

But Problem is loadScrollViewWithPage method has arguments. that method is like this

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

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

How could I call for this method? Please give me a help. thanks in advanced.

我怎么能打电话给这个方法?请给我一个帮助。先谢谢了。

2 个解决方案

#1


3  

- (IBAction) updateButtonPressed{
   int tempValue=5;
   [self loadScrollViewWithPage:tempValue];
}

#2


4  

If I understand correctly, you are wondering how to pass arguments along with messages to objects, is that right? Try:

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

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

I suggest you read up on the Objective-C language in general, though.

不过,我建议你阅读Objective-C语言。

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

#1


3  

- (IBAction) updateButtonPressed{
   int tempValue=5;
   [self loadScrollViewWithPage:tempValue];
}

#2


4  

If I understand correctly, you are wondering how to pass arguments along with messages to objects, is that right? Try:

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

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

I suggest you read up on the Objective-C language in general, though.

不过,我建议你阅读Objective-C语言。

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