V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Linxing
V2EX  ›  iDev

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

  •  
  •   Linxing ·
    linxing · 2014-02-20 17:18:22 +08:00 · 2865 次点击
    这是一个创建于 3717 天前的主题,其中的信息可能已经有所发展或是发生改变。




    不使用NSTimer手动获取json内容是可以的...
    11 条回复    1970-01-01 08:00:00 +08:00
    wezzard
        1
    wezzard  
       2014-02-20 18:05:03 +08:00   ❤️ 1
    建议使用
    + (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
        2
    Linxing  
    OP
       2014-02-20 19:53:43 +08:00
    @wezzard 我是这么创建的啊....
    alexrezit
        3
    alexrezit  
       2014-02-20 19:54:16 +08:00
    [timer fire];

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

    -addTimer:forMode:
    alexrezit
        5
    alexrezit  
       2014-02-20 19:55:48 +08:00
    我好像又在夢游了... 抱歉!
    Linxing
        6
    Linxing  
    OP
       2014-02-20 19:56:33 +08:00
    @alexrezit 需要fire?
    alexrezit
        7
    alexrezit  
       2014-02-20 19:58:40 +08:00
    @Linxing
    你的代碼不是這麼說的... 用 scheduledTimer prefix 的 method 就可以了.
    也不清楚為什麼要重復獲取...
    alexrezit
        8
    alexrezit  
       2014-02-20 19:59:01 +08:00
    @Linxing
    忽略那條回復就好了.
    Linxing
        9
    Linxing  
    OP
       2014-02-20 20:04:22 +08:00
    @alexrezit 好吧..就想写个NSTimer,看书看到这..
    Linxing
        10
    Linxing  
    OP
       2014-02-20 20:07:51 +08:00
    @alexrezit 改好了,确实是我自己代码写得问题,scheduledTimer可以。。谢了
    Linxing
        11
    Linxing  
    OP
       2014-02-20 20:08:03 +08:00
    @Linxing 谢了..
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5701 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 06:28 · PVG 14:28 · LAX 23:28 · JFK 02:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.