Note that there are some explanatory texts on larger screens.

plurals
  1. POperformSelector:withObject:afterDelay: not working from scrollViewDidZoom
    primarykey
    data
    text
    <p>I feel like I should know this but I've been stumped for hours now and I've run out of ideas.</p> <p>The theory is simple, the user manipulates the zoom and positioning in a scrollview using a pinch. If they hold that pinch for a short period of time then the scrollview records the zoom level and content offsets.</p> <p>So I thought I'd start a performSelector:withObject:withDelay on the scrollViewDidZoom delegate method. If it expires then I record the settings. I delete the scheduled call every time scrollViewDidZoom is called and when the pinch gesture finishes.</p> <p>This is what I have:</p> <pre><code>- (void)scrollViewDidZoom:(UIScrollView *)scrollView{ NSLog(@"resetting timer"); [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(positionLock) object:nil]; [self performSelector:@selector(positionLock) withObject:nil afterDelay:0.4]; } -(void)positionLock{ NSLog(@"position locked "); } - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{ NSLog(@"deleting timer"); [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(positionLock) object:nil]; } </code></pre> <p>This is the output:</p> <p>2010-05-19 22:43:01.931 resetting timer<br> 2010-05-19 22:43:01.964 resetting timer<br> 2010-05-19 22:43:02.231 resetting timer<br> 2010-05-19 22:43:02.253 resetting timer<br> 2010-05-19 22:43:02.269 resetting timer<br> 2010-05-19 22:43:02.298 resetting timer<br> 2010-05-19 22:43:05.399 deleting timer </p> <p>As you can see the delay between the last and second last events should have been more than enough for the delayed selector call to execute.</p> <p>If I replace performSelector:withObject:withDelay with plain old performSelector: I get this:</p> <p>2010-05-19 23:08:30.333 resetting timer<br> 2010-05-19 23:08:30.333 position locked<br> 2010-05-19 23:08:30.366 resetting timer<br> 2010-05-19 23:08:30.367 position locked<br> 2010-05-19 23:08:30.688 deleting timer </p> <p>Which isn't what I want but serves to show that it's only the delay that's causing it to not function, not something to do with the selector not being declared in the header, being misspelt or any other reason.</p> <p>Any ideas as to why it's not working? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload