zoukankan      html  css  js  c++  java
  • iPhone开发之NSRunLoop简单使用

    //
    //  ViewController.m
    //  RunLoopDemo
    //
    //  Created by Fox on 12-5-13.
    //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	
        //使用NSTimer创建定时器
        NSTimeInterval timeInterval = 2;//间隔时间
        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];
        
        
        //使用RunLoop创建NSTimer对象
        NSRunLoop *theRunLoop = [NSRunLoop currentRunLoop];//获得当前的RunLoop
        NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:2.0];//创建对象,指定首次启动的时间
        NSTimer *theTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:2 target:self selector:@selector(timerMethod2) userInfo:nil repeats:YES];
        [theRunLoop addTimer:theTimer forMode:NSDefaultRunLoopMode];
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    - (void)timerMethod{
    
        NSLog(@"NSTimer1执行");
    }
    - (void)timerMethod2{
    
         NSLog(@"NSTimer2执行");
    }
    
    
    @end
    

      

  • 相关阅读:
    梯度下降-Momentum
    6-10-HIRP OPEN 2016
    机器学习数目推荐
    《统计、计算和未来-李航》读后感
    MongoDB $关键字 $修改器
    MongoDB数据类型
    MongoDB操作(增删改查)
    MongoDB安装及开启(Windows)
    第七周:论文泛读(二)
    第六周:论文泛读(一)
  • 原文地址:https://www.cnblogs.com/foxmin/p/2498122.html
Copyright © 2011-2022 走看看