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

i have this code for autoscrolling of tableviewcell,when i click this button it starts scrolling automatically,but i want to stop this in the another button click.How to stop the above autoscrolling in a button click. TRhanks in advance.

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38
stackiphone
  • 1,245
  • 3
  • 19
  • 41

2 Answers2

3

Save the reference autoscrollTimer, and then use NSTimer's invalidate method to kill the timer. Or, alternately, as suggested, use scrollToRowAtIndexPath:atScrollPosition: instead.

Mustafa
  • 20,504
  • 42
  • 146
  • 209
  • i implement the Invlidate method in another button click to stop the autoscroll,it works fine,but after that i click the autoscroll button it is not working. – stackiphone Jan 14 '12 at 06:59
  • That's because invalidate doesn't `nil` the timer. And you're code initializes and restarts the timer IF it's nil. So, go ahead an nil the timer (when it's invalidated) as well, or change your `_clickautoscroll` method appropriately. – Mustafa Jan 15 '12 at 13:39
2

Try using scrollToRowAtIndexPath:atScrollPosition: instead:

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

Here, you can scroll to the next row by doing something like toRow + 1, and maybe somewhere in there throw in an increment statement.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186