Iphone Geasture识别器

Iphone Geasture识别器,iphone,Iphone,我在UISWitchControl中有激活autoscroll功能的代码 -(IBAction)_clickautoscroll:(id)sender { if(switchcontrolautoscroll.on){ if autoscrollTimer== nil) { autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(55.0/1000.0)

我在UISWitchControl中有激活autoscroll功能的代码

    -(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]; 
}
它工作得很好,但我有很长的手势识别器来结束代码的自动滚动

-(void) handleLongPressOnUndoGesture:(UILongPressGestureRecognizer*)recognizer {
    //[switchcontrolautoscroll setOn:NO animated:YES];
    [autoscrollTimer invalidate];
     [self.table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
但当我点击taptohold时,它会停止自动滚动,但应用程序会崩溃。 我的代码有什么缺陷吗。
谢谢。

NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
创建自动释放变量,您不保留它

将autoscrollTimer设置为保留属性,并使用self.autoscrollTimer进行设置

在调用HandleLongPressonEndoshive时,它可能已经被释放,这就是崩溃的原因