求大神帮忙看下 NSTimer 的问题...

2014-02-20 17:18:22 +08:00
 Linxing
https://gist.github.com/linxing/9109750

https://gist.github.com/linxing/9109795

不使用NSTimer手动获取json内容是可以的...
https://gist.github.com/linxing/9109859
2867 次点击
所在节点    iDev
11 条回复
wezzard
2014-02-20 18:05:03 +08:00
建议使用
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
或者
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds invocation:(NSInvocation *)invocation repeats:(BOOL)repeats
来创建 NSTimer 对象,这样 NSTimer 一旦被创建出来就被放到 Runloop 上了。不然你还得手动将其放置在 Runloop 上。
Linxing
2014-02-20 19:53:43 +08:00
@wezzard 我是这么创建的啊....
alexrezit
2014-02-20 19:54:16 +08:00
[timer fire];

這樣?
alexrezit
2014-02-20 19:55:34 +08:00
噢...

-addTimer:forMode:
alexrezit
2014-02-20 19:55:48 +08:00
我好像又在夢游了... 抱歉!
Linxing
2014-02-20 19:56:33 +08:00
@alexrezit 需要fire?
alexrezit
2014-02-20 19:58:40 +08:00
@Linxing
你的代碼不是這麼說的... 用 scheduledTimer prefix 的 method 就可以了.
也不清楚為什麼要重復獲取...
alexrezit
2014-02-20 19:59:01 +08:00
@Linxing
忽略那條回復就好了.
Linxing
2014-02-20 20:04:22 +08:00
@alexrezit 好吧..就想写个NSTimer,看书看到这..
Linxing
2014-02-20 20:07:51 +08:00
@alexrezit 改好了,确实是我自己代码写得问题,scheduledTimer可以。。谢了
Linxing
2014-02-20 20:08:03 +08:00
@Linxing 谢了..

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

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

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

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

© 2021 V2EX