在.NET中,當我有了一個事件我可以註冊通過委託來處理該事件的對象:與.NET代理相當的Objective-C是什麼?
void Test()
{
Button button = new Button();
button.Click += new EventHandler(OnClick);
}
void OnClick(object sender, EventArgs e)
{
text1.Text = "The Button Was Clicked";
}
我怎麼做這樣的事情在Objective-C?具體來說,我試圖處理一個SneakyButton的ccTouchEnded。我認爲它會是這樣的:
SneakyButton* mybutton = [SneakyButton button];
[mybutton ccTouchEnded:self.onButtonDown];
- (void)onButtonDown:(UITouch *)touch withEvent:(UIEvent *)event
{
CCLOG(@"The Button Was Clicked");
}