2012-02-23 74 views
0

我应该怎么做的函数签名下方多加一个参数:添加参数

- (void)locationPondSizeViewController: 
(LocationPondSizeViewController *)controller 
        didSelectPondSize:(NSString *)thePondSize 
{ 
    .... 
} 

它实际上是一个委托函数和调用:

[self.delegate locationPondSizeViewController:self 
           didSelectPondSize:thePondSize]; 

而且帮助我了解委托名称,函数名称,参数以及此签名中的返回类型。

+1

只需追加'参数1:(ID)参数1参数:(ID)参数2 '给方法名称? – Costique 2012-02-23 06:35:46

回答

1

这听起来有点像一门功课的问题...

Objective-C的声明:

void locationPondSizeViewController:didSelectPondSize:(LocationPondSizeViewController *controller, NSString *thePondSize) { ... } 

- (void)locationPondSizeViewController:(LocationPondSizeViewController *)controller 
        didSelectPondSize:(NSString *)thePondSize { ... } 

会使用更多的传统样式声明如被写在一个语言

(尽管大多数语言不允许:在标识符中)

所以方法/函数名称是locationPondSizeViewController:didSelectPondSize:,它需要LocationPondSizeViewController *NSString *类型的两个参数,并且不返回(void),即其过程。参数在它的主体中被称为controllerthePondSize

您可以通过根据需要添加“名称> :(<型>)<参数名的<部分>”多次以进一步扩展参数。

毫无意义的珍闻:你其实并不需要任何先于冒号,这是方法::的有效的定义:

- (int) :(int)x :(int)y { return x + y; } 
1

这里是添加你的方法有一个额外的参数的例子:

- (void)locationPondSizeViewController:(LocationPondSizeViewController *)controller 
        didSelectPondSize:(NSString *)thePondSize 
         withNewParameter:(NSObject*)newParam 
{ 
    ... 
} 

而且这里是你会怎么称呼它:

[self.delegate locationPondSizeViewController:self didSelectPondSize:thePondSize withNewParameter:myParam]; 

在这个例子中的方法签名是- locationPondSizeViewController:didSelectPondSize:withNewParameter:

它需要三个参数:1)controller,2)thePondSize和3)newParam

该方法的返回类型为void

+1

这是完美的。太奇怪了,注意他没有在'locationPondSizeViewController:'之后和'(LocationPondSizeViewController *)控制器之前放置一个返回值,这使得它很难阅读。如果您愿意,也可以将整个方法签名放在一行中,并在每个部分之间留出空格。 – 2012-02-23 06:51:24