Geasture распознаватель сомнений - PullRequest
0 голосов
/ 24 января 2012

haii У меня есть этот код в UISWitchControl для активации функции автопрокрутки

    -(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];
}

но когда я нажимаю на кнопку, она останавливает автопрокрутку, но происходит сбой приложения. есть ли дефект в моем коде. Спасибо.

1 Ответ

1 голос
/ 24 января 2012

NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: создает автоматически выпущенную переменную, а вы ее не сохраняете.

Сделать autoscrollTimer сохраняемым свойством и установить его с помощью self.autoscrollTimer

Вероятно, он был выпущен к тому времени, когда handleLongPressOnUndoGesture вызывается, и именно здесь вы получаете сбой.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...