Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-19-2010, 05:47 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 8
shadowmatter is on a distinguished road
Default performSelector unable to run while UITableView is dragged?

Hi all,

I have a UITableViewController with its default UITableView. I begin slowly dragging the table with my finger to scroll, i.e. not flicking it with my finger. Every time the table moves on-screen the scrollViewDidScroll method of the controller is called; when some conditions I've specified are met, one of these calls to scrollViewDidScroll uses performSelector:withObject:afterDelay to schedule some action at a later time.

However, I'm finding that the action will not execute until I release my finger. For example, if I set the afterDelay parameter to 2 seconds, but hold my finger for 5 seconds, when I release my finger and the action executes it's 3 seconds too late. Is there any way to allow the action (which is to update the UI and so must run in the main thread) to execute while the finger is still against the screen?

Thanks!
shadowmatter is offline   Reply With Quote
Old 11-19-2010, 08:33 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by shadowmatter View Post
Hi all,

I have a UITableViewController with its default UITableView. I begin slowly dragging the table with my finger to scroll, i.e. not flicking it with my finger. Every time the table moves on-screen the scrollViewDidScroll method of the controller is called; when some conditions I've specified are met, one of these calls to scrollViewDidScroll uses performSelector:withObject:afterDelay to schedule some action at a later time.

However, I'm finding that the action will not execute until I release my finger. For example, if I set the afterDelay parameter to 2 seconds, but hold my finger for 5 seconds, when I release my finger and the action executes it's 3 seconds too late. Is there any way to allow the action (which is to update the UI and so must run in the main thread) to execute while the finger is still against the screen?

Thanks!
The whole point of performSelector:withObject:afterDelay: is that it sets up a call to occur after your code returns to the main event loop.

If you run code in a tight loop that doesn't allow the event loop to run, the method doesn't get called until your code returns. It sounds like the scroll view keeps the app in a loop handling the user drag action until release. That surprises me, since the scroll view needs to handle touchesMoved events. Nevertheless, the answer is that you can't use performSelector:withObject:afterDelay:
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-20-2010, 12:33 AM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

While you are scrolling the event loop runs in NSEventTrackingRunLoopMode, and will not trigger normal timer events and performSelectors. This is done to keep the UI snappy.

You can create an NSTimer that will run in that loop though, by creating and scheduling it yourself. See the addTimer answer to this question:

UIScrollView pauses NSTimer until scrolling finishes - Stack Overflow
__________________

Free Games!
smasher is offline   Reply With Quote
Old 11-21-2010, 03:28 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 8
shadowmatter is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
While you are scrolling the event loop runs in NSEventTrackingRunLoopMode, and will not trigger normal timer events and performSelectors. This is done to keep the UI snappy.

You can create an NSTimer that will run in that loop though, by creating and scheduling it yourself. See the addTimer answer to this question:

UIScrollView pauses NSTimer until scrolling finishes - Stack Overflow
The solution at Stack Overflow worked perfectly, and the docs on run loops were very informative. Thanks for the help, smasher!
shadowmatter is offline   Reply With Quote
Reply

Bookmarks

Tags
cocoa-touch, iphone, nsrunloop, uitableview, uitableviewcontroller

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 373
7 members and 366 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0