zoukankan      html  css  js  c++  java
  • NSTimer

    NSTimer 解析

    iphone为我们提供了一个很强大得时间定时器 NSTimer
    他可以完成任何定时功能:
    我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理
    delegate和事件处理方法@selector();就可以用
    + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo; 来初始化一个 时间定时器
    下面我写了一个很简单得例子

    NSTimer *animateTimer;//定义一个类的成员变量

    //初始化成员变量的值,启动Selctor()中调用的函数是可以有参数的,如果有参数,定义函数的时候记住别丢掉这个函数

    animateTimer = [NSTimer  scheduledTimerWithTimeInterval:1.0 target:self  selector:@selector(showAlert1) userInfo:nil repeats:YES];

    //调用Fire成员函数,启动定时器

    [animateTimer fire];

    //NSTimer调用所响应的函数

    -(void)showAlert1

    {

       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"message"

      message:@"love you "

      delegate:nil 

       cancelButtonTitle:@"ok"

      otherButtonTitles:nil];

    [alertView show];

    [alertView release];

    }

    THE END !

  • 相关阅读:
    LineageOS将会重生 CyanogenMod会继续下去
    著名第三方ROM Cyanogen Mod宣布关闭
    Service Worker API (mozilla) vs Service Workers (google)
    Service Worker 入门
    Web新技术:PWA
    (OK) 编译 cm-13-kiwi for (华为 荣耀 5X)
    4
    3
    2
    1
  • 原文地址:https://www.cnblogs.com/xingchen/p/2107971.html
Copyright © 2011-2022 走看看