In my app,
I have a 3 tab,
On the first tab I have a timer that is started when Start button is pressed.
When we come from the another tab, timer is not getting update.
For updating the timer, I use below code:
myticker = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(ShowActicity) userInfo:nil repeats:YES];
-(void)ShowActicity
{
Here I have the ticks,minute,hour values
ticks =ticks + 1;
if(ticks > 59)
{
minute = minute + 1;
ticks = 0;
if(minute > 59)
{
hour = hour + 1;
minute = 0;
if(hour > 23)
{
hour = 0;
}
}
}
[lbl_timer setText:[NSString stringWithFormat:@"%02d:%02d:%02d",hour,minute,ticks]];
}
My timer is updating fine with Base SDK iOS 4.2 but not working on iOS 5. What could be wrong?
THis may not be your problem but the selector is incorrect, from the Apple docs:
The selector must have the following signature:
- (void)timerFireMethod:(NSTimer*)theTimer
so your NSTimer call should be (notice the trailing ":"
myticker = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(ShowActicity:) userInfo:nil repeats:YES];
and the target method have the signature:
- (void)ShowActicity:(NSTimer*)theTimer
Note, it is Objective-C convention to name methods with an initial lowercase letter, classes with a leading upper case character.
In 4.3 project main.m replace with ios5 main.m File. In appdelegate change the
@interface SimpleTimerAppAppDelegate : NSObject
with
@interface SimpleTimerAppAppDelegate : UIResponder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.