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
    

      

  • 相关阅读:
    POJ2456 Aggressive cows
    Binary Search
    Leetcode1025 Divisor Game
    我的高中生活目标
    leetcode155 min stack
    Leetcode983 Minimum Cost For Tickets
    合并两个有序数组
    X的平方根
    力扣第35场双周赛
    整数反转
  • 原文地址:https://www.cnblogs.com/foxmin/p/2498122.html
Copyright © 2011-2022 走看看