How to get a UITableview to go to the top of page on reload?

前端 未结 13 2159
一个人的身影
一个人的身影 2021-02-01 02:30

I am trying to get a UITableview to go to the top of the page when I reload the table data when I call the following from

- (void)pickerView:(UIPickerView *)pic         


        
13条回答
  •  無奈伤痛
    2021-02-01 02:57

    To scroll to a specific section you need to specify the index path to it:

    NSIndexPath *topPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [TableView scrollToRowAtIndexPath:topPath
                     atScrollPosition:UITableViewScrollPositionTop
                             animated:YES];
    

    If you are uncertain about the number of rows in your tableView. Use the following:

    NSIndexPath *topPath = [NSIndexPath indexPathForRow:NSNotFound inSection:0];
    [TableView scrollToRowAtIndexPath:topPath
                     atScrollPosition:UITableViewScrollPositionTop
                             animated:YES];
    

提交回复
热议问题