iPhone SDK - How to scroll a UITableView programmatically with animation?

前端 未结 4 1459
傲寒
傲寒 2021-02-19 21:15

How would I scroll a UITableView to a specific position with an animation?

Currently I\'m using this code to jump to a position:

 //tableController ->         


        
4条回答
  •  别那么骄傲
    2021-02-19 21:54

    It works fine for me:

    -(void) viewDidAppear:(BOOL)animated{
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:n inSection:0];
        [self.tableView scrollToRowAtIndexPath:indexPath
                        atScrollPosition:UITableViewScrollPositionTop
                                animated:YES];
    
    }
    

    To be sure that this is called only once, you can make a verification like this:

    if(!isInitialized){
       isInitialized = YES;
       ....
    }
    

提交回复
热议问题