Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 13, 2011, 12:43 AM   #1
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Scrolling blocks thread?

I have a UILabel that informs the user how much time is left in a round of my game. Here's the code:

Code:
startDate = [[NSDate alloc] init];
updateClockTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateClock) userInfo:nil repeats:YES];
Code:
- (void)updateClock
{
    double totalSecs = [startDate timeIntervalSinceNow] + SECS_PER_ROUND;
    int mins = totalSecs/60;
    int secs = (int)totalSecs%60;
    int deca = (int)(totalSecs * 10)%10;
    rightScore.text = [NSString stringWithFormat:@"%i:%.2i.%i", mins, secs, deca];
}
It normally displays and updates properly, except when a UIScrollView is scrolling. I suspect the action of scrolling is somehow blocking the main thread, but I'm not really sure as I don't have a particularly firm grasp on understanding how threading works.

Could someone offer me a solution for how to make my countdown timer to continue updating even when scrolling?
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.

Last edited by ArtOfWarfare; Aug 13, 2011 at 04:52 PM.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 13, 2011, 01:14 AM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
While scrolling, the main run loop moves out of the default mode. You can try manually adding your NSTimer to the main NSRunLoop so it fires in all modes.

Code:
updateClockTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateClock) userInfo:NULL repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:updateClockTimer forMode:NSRunLoopCommonModes];
jiminaus is offline   0 Reply With Quote
Old Aug 13, 2011, 09:26 AM   #3
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by jiminaus View Post
While scrolling, the main run loop moves out of the default mode. You can try manually adding your NSTimer to the main NSRunLoop so it fires in all modes.

Code:
updateClockTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateClock) userInfo:NULL repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:updateClockTimer forMode:NSRunLoopCommonModes];
Thanks! That worked perfectly!
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Blocks app alaahershy iPhone and iPod touch Apps 0 Nov 13, 2013 12:55 PM
Windows 8.1 blocks apple.com website Mac32 Windows, Linux & Others on the Mac 6 Nov 3, 2013 11:52 AM
General: Is there anything that blocks app updates guitarmandp Jailbreaks and iOS Hacks 2 May 7, 2013 09:49 AM
Natural scrolling for trackpads, old scrolling for mouses? JesperA OS X 10.8 Mountain Lion 1 Nov 29, 2012 11:01 PM

Forum Jump

All times are GMT -5. The time now is 06:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC