Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performSelector unable to run while UITableView is dragged?

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!

like image 601
shadowmatter Avatar asked Mar 03 '26 00:03

shadowmatter


1 Answers

This is because when a UIScrollView (UITableView's superclass) is scrolling, it changes its runloop in order to prioritize the scrollView over whatever the application was doing. This is happening to make sure scrolling is as smooth as it can be.

try using this version of delayed method:

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes;

for the modes, I'd suggest starting with an array that contains the following: [[NSRunloop currentRunLoop] currentMode], NSDefaultRunLoopMode

like image 51
Pier-Olivier Thibault Avatar answered Mar 04 '26 13:03

Pier-Olivier Thibault



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!