Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 13, 2011, 01: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?
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Aug 13, 2011 at 05:52 PM.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 13, 2011, 02: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, 10: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!
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
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 01:55 PM
Windows 8.1 blocks apple.com website Mac32 Windows, Linux & Others on the Mac 6 Nov 3, 2013 12:52 PM
General: Is there anything that blocks app updates guitarmandp Jailbreaks and iOS Hacks 2 May 7, 2013 10:49 AM
Natural scrolling for trackpads, old scrolling for mouses? JesperA OS X 10.8 Mountain Lion 1 Nov 30, 2012 12:01 AM

Forum Jump

All times are GMT -5. The time now is 09:34 AM.

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

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