在 .Net 中,当我有一个具有事件的对象时,我可以注册以通过委托处理该事件:
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");
}