zoukankan      html  css  js  c++  java
  • timer

    Objective-C Timer(实用)

     (2011-04-07 10:38:51)
    标签: 

    ipad

     

    iphone

     

    ios

     

    it

     

    objective-c

     

    开发

     

    移动

    分类: iPhone


    //I am creating a dictionary object that I can pass to my selector method.


    NSArray *keys = [NSArray arrayWithObjects:@"key1"@"key2"@"key3"nil];


    NSArray *objects = [NSArray arrayWithObjects:@"value1"@"value2"@"value3"nil];


    NSDictionary *myDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];


    [NSTimer scheduledTimerWithTimeInterval:1.0 target:selfselector:@selector(fireTimer:) userInfo:myDictionary repeats:YES];


    //The fireTimer() is the selector method I setup above


    - (void) fireTimer:(NSTimer*)theTimer {

    for (id key in [theTimer userInfo]) {

    NSLog(@"key: %@, value: %@", key, [[theTimer userInfoobjectForKey:key]);

    }

    //kill the timer

    [theTimer invalidate];

    theTimer = nil;

    }


     


    //here is a similar example but with using an NSNumber


    NSNumber *myInt = [NSNumber numberWithInt:4];


    [NSTimer scheduledTimerWithTimeInterval:1.0 target:selfselector:@selector(fireTimer:) userInfo:myInt repeats:YES];


    - (void) fireTimer:(NSTimer*)theTimer {

    NSLog(@" %i ", [[theTimer userInfo] integerValue]);

    [theTimer invalidate];

    theTimer = nil;

    }

  • 相关阅读:
    hdu5119 DP
    poj3692 最大点权独立集/最大独立集
    poj2125 最小点权覆盖集
    二分图总结
    poj2531 Network Saboteur
    poj1573 Robot Motion
    poj2632 Crashing Robots
    poj1068
    动态规划的思考(三)
    代刷题目分类(三)
  • 原文地址:https://www.cnblogs.com/moonvan/p/2248521.html
Copyright © 2011-2022 走看看