Code:
RootViewController.h
#import <UIKit/UIKit.h>@interface rootviewcontroller:uiviewcontroller{ // define Timer Nstimer * timer;} @end
Rootviewcontroller.m
-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated];//Turn the timer back on[Timer setfiredate:[nsdate Distantpast]; }-(void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated];//Temporarily turn off the timer.[Timer setfiredate:[nsdate distantfuture];} - (void) viewdidload{[Super Viewdidload];// Do any additional setup after loading the View. Self.title=@ " timer use " ; // When the page with the timer is on, the timer is started. When leaving the page where the timer is located, the timer stops and the timer restarts when it enters the secondary. // timer function. Timer=[nstimer scheduledtimerwithtimeinterval:0.1 Target:self selector: @selector (loaddata) Userinfo:nil Repeats:yes]; }-(void) loaddata{NSLog ( @ "i Love you! "
"Code Note" Ios-nstimer