2012-07-24 38 views
0

我想要一个UIButton这样工作:首先点击它,运行start_method;点击它,运行stop_method;点击它再次运行start_method;第四次点击它,再次运行stop_method。这样一个循环。如何在一个UIButton中实现Start和Stop动作?

当我设置按钮:

[button addTarget:self action:@selector(start_method:) forControlEvents:UIControlEventTouchDown]; 
    [button addTarget:self action:@selector(stop_method:) forControlEvents:UIControlEventTouchDownRepeat]; 

对此的反应,只要你点击它两个动作。

有什么建议吗?

回答

2

将一个布尔值添加到您的视图控制器,并将其设置为false。然后当你按下按钮时,检查布尔值的值,然后翻转它,然后运行start或stop方法。

+0

简单而漂亮。为什么我不这样想! – Maadiah 2012-07-24 03:00:16

+0

我很乐意提供帮助!我希望你的应用程序做得很好! – portforwardpodcast 2012-07-24 08:37:02

相关问题