2012-01-14 61 views
2
-(IBAction)_clickautoscroll:(id)sender 
{ 
    NSTimer *autoscrollTimer; 
    if (autoscrollTimer == nil) { 
     autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(55.0/1000.0) 
                  target:self 
                 selector:@selector(autoscrollTimerFired:) 
                 userInfo:nil 
                  repeats:YES]; 
    } 
} 
- (void)autoscrollTimerFired:(NSTimer*)timer { 
    CGPoint scrollPoint = self.table.contentOffset; 
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); 
    [self.table setContentOffset:scrollPoint animated:NO]; 
} 

我有這樣的代碼tableviewcell的自動滾動,當我點擊這個按鈕,它會自動開始滾動,但我想制止這種在另一個按鈕click.How停止上述自動滾動在點擊一個按鈕。 提前感謝。自動滾屏在Tableviewcell

回答

3

保存參考autoscrollTimer,然後用NSTimerinvalidate方法殺死定時器。或者,如建議的那樣,或者使用scrollToRowAtIndexPath:atScrollPosition:

+0

我實現了Invlidate方法,在另一個按鈕點擊停止自動滾動,它工作正常,但之後我點擊自動滾動按鈕它不工作。 – stackiphone 2012-01-14 06:59:06

+0

這是因爲無效不會使計時器無效。你的代碼初始化並重新啓動定時器,如果它是零。因此,繼續定時器(當它失效時),或者適當地改變'_clickautoscroll'方法。 – Mustafa 2012-01-15 13:39:42

2

嘗試使用scrollToRowAtIndexPath:atScrollPosition:代替:

[self.table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:toRow inSection:someSection] 
        atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 

在這裏,你可以做這樣的事情toRow + 1滾動到下一行,並在增量聲明有可能的地方扔。

+0

先生,什麼是torow和一些部分? – stackiphone 2012-01-14 07:00:58

+0

**'toRow' **是您想要滾動到的行。 **'inSection' **是'toRow'所在的部分。 – WrightsCS 2012-01-14 10:02:22