NSRunLoop&NSTimer混合使用

//

//  ViewController.m

//  NSRunLoop

//

//  Created by JackMeng on 13-11-14.

//  Copyright (c) 2013 JackMeng. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    

    //使用NSTimer创建定时器

    NSTimeInterval timeInterval = 1;//间隔时间

    [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)timerMethod{

    

    NSLog(@"我是定时器one");

}

- (void)timerMethod2{

    

    NSLog(@"我是定时器two");

}

- (void)viewDidUnload

{

    [super viewDidUnload];

    // Release any retained subviews of the main view.

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}



- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

你可能感兴趣的:(NSTimer,NSRunLoop)