菜鸟 iOS 开发求助

2015-10-18 22:41:51 +08:00
 lisonfan

做的一个倒计时的例子,代码如下:
现在的问题是 _timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(tickAction) userInfo:nil repeats:YES]; 这段代码不起作用。。

import "ViewController.h"

@interface ViewController (){
UIDatePicker * _myPicker;
NSTimeInterval _sec;
UILabel * _label;
UIButton * _btn;
NSTimer * _timer;
}

@end

@implementation ViewController

@end

598 次点击
所在节点    C
3 条回复
lisonfan
2015-10-18 23:03:55 +08:00
在 alertAction 中添加了
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
能实现倒计时了。
lisonfan
2015-10-18 23:17:17 +08:00
不知道为什么,会有两秒的延迟
lisonfan
2015-10-18 23:34:43 +08:00
延迟的问题解决了。。
tickAction 里 把 _sec-- 改成 --_sec

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/229048

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX