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
    

      

  • 相关阅读:
    linux配置虚拟主机
    mysql允许远程登录
    php优化
    php socket 函数
    1-- prometheus安装、图形化界面
    Ansible Roles
    Ansible 的 Playbook
    Ansible 变量
    Ansible 模块
    Ansible入门;Ansible ad-hoc; ansible-vault加密工具 ;ansible-console
  • 原文地址:https://www.cnblogs.com/foxmin/p/2498122.html
Copyright © 2011-2022 走看看