// ide
// ViewController.m oop
// NSRunLoop spa
// .net
// Created by JackMeng on 13-11-14. 對象
// Copyright (c) 2013年 JackMeng. All rights reserved. get
// it
#import "ViewController.h" io
@interface ViewController () class
@end import
@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.
}