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 601
 
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 online now   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 601
 
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 online now   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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Safari/Facebook issues with scrolling natekettles Mac Applications and Mac App Store 2 May 8, 2011 10:29 PM
possible to block individual user's comments when viewing threads? waiting Site and Forum Feedback 2 Mar 17, 2011 03:25 AM
Block Shooter HD Free is out now! Hurry up!!! wodemobile iPad Apps 8 Feb 1, 2011 02:55 PM
scroll a uitextfield and a uitextview in a uiscrollview franium iPhone/iPad Programming 14 Dec 4, 2010 02:51 AM
I think I might've changed the scrolling style somehow R94N OS X 2 Nov 5, 2010 10:54 AM


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

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

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