NStimer 和 for 循环
我正在为此苦苦挣扎。我看到一些代码可以执行此操作:
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doActions) userInfo:nil repeats:YES];
}
然后在 doActions 中调用它。
问题是我想在按下按钮时调用它,并且执行操作是一个IBaction
。我不断收到 sigAbrt
。
有人可以给我一些示例代码,您可以在按下按钮时每 1 秒将标签从“开”更改为“关”吗?
编辑
我的意思是如果 doActions 看起来像这样
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
I'm struggling with this. I saw some code where you can do this :
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doActions) userInfo:nil repeats:YES];
}
Then call it in doActions.
Problem is i want to call it while a button is being pressed, and do actions is an IBaction
. I keep getting a sigAbrt
.
Can someone give me some sample code where you cay change a label from 'on' to 'off' every 1 second while a button is being pressed?
EDIT
i mean if doActions looks like this
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我仍然不清楚你想要实现什么:毕竟,如果你只是用简单的英语写下来的话,我会发现它会容易得多。
也就是说,我认为这将帮助您到达您想去的地方:
根据您想要执行的操作,
startToggling:
需要在touchUpInside
或touchDown
上发送。在第二种情况下,可能需要在按钮的任何touchUp...
事件上调用stopToggling:
。It still isn't clear to me, what you're trying to accomplish: I would have found it much easier, if you simply had it written down in plain english, after all.
That said, here's what I think will get you where you want to go:
Depending on what exactly you want to do,
startToggling:
needs to be sent on eithertouchUpInside
ortouchDown
. In the second case,stopToggling:
probably needs to be called on anytouchUp...
event of the button.