haii i have this code in UISWitchControl for activating the autoscroll function
-(IBAction)_clickautoscroll:(id)sender
{
if(switchcontrolautoscroll.on){
if autoscrollTimer== nil) {
autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(55.0/1000.0)
target:self
selector:@selector(autoscrollTimerFired:)
userInfo:nil
repeats:YES];
}
}
else{
[switchcontrolautoscroll setOn:NO animated:YES];
[autoscrollTimer invalidate];
[self.table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
}
- (void)autoscrollTimerFired:(NSTimer*)timer {
CGPoint scrollPoint = self.table.contentOffset;
scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1);
[self.table setContentOffset:scrollPoint animated:NO];
}
It works fine,but i have long-gesture-recognizer to end the autoscroll the code is
-(void) handleLongPressOnUndoGesture:(UILongPressGestureRecognizer*)recognizer {
//[switchcontrolautoscroll setOn:NO animated:YES];
[autoscrollTimer invalidate];
[self.table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
but when i tap taptohold it stops the autoscroll and but the application crash.
is there any defect in my code.
Thanks.
NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:creates an autoreleased variable, and you are not retaining it.Make autoscrollTimer a retained property and set it using self.autoscrollTimer
It has probably been released by the time handleLongPressOnUndoGesture is called, and that’s where you get the crash.