2010-09-14 40 views
2

我在哪裏可以找到內置類(如UIGestureRecognizer或UIMenuItem等)中的回調方法的方法簽名?Objective-C中選擇器的查找方法簽名C

例如,用於文檔狀態UIMenuItem

initWithTitle:動作:
創建並返回與給定標題和動作初始化的菜單項對象。

- (ID)initWithTitle:(NSString的)標題行動:(SEL)動作

參數
標題
菜單項的標題。
動作
一個選擇器,標識響應器對象調用的方法,以處理由菜單項表示的命令。
返回值
已初始化的UIMenuItem對象,或者如果在創建對象時出現問題,則返回nil。

我怎麼知道'action'可能接收到什麼參數?

回答

5

請參閱Target-Action Mechanism in UIKit的文檔。具體來說它提到以下情況:

在與所述應用程序包,其中一個操作方法可以僅具有一個或也許兩個有效簽名相反,UIKit框架允許三種不同形式的動作選擇的:

  • - (void)action
  • - (void)action:(id)sender
  • - (void)action:(id)sender forEvent:(UIEvent *)event
1

'動作' 是可可觸摸/ UIKit的一個約定:Target-Action in UIKit

操作可以有以下三種簽名UIKit中:

- (void)action 
- (void)action:(id)sender 
- (void)action:(id)sender forEvent:(UIEvent *)event 
+1

UIKit [有點不同](http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW44)在慣例。 – 2010-09-14 23:23:16

+0

這是爲可可;在Cocoa Touch中,動作方法可以採取以下三種形式中的任意一種,所有這些都記錄在這裏:http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html% 23 // apple_ref/DOC/UID/TP40002974-CH7-SW44 – 2010-09-14 23:24:02