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

前端 未结 13 1873
一个人的身影
一个人的身影 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:59

    If you scroll before reloading and the number of rows decreases, you can have some strange animating behavior. To ensure the scrolling happens after reload, use a method like this:

    - (void)reloadTableViewAndScrollToTop:(BOOL)scrollToTop {
        [self.tableView reloadData];
        if (scrollToTop) {
            [self.tableView setContentOffset:CGPointZero animated:YES];
        }
    }
    
    0 讨论(0)
提交回复
热议问题