UITableView Refresh without scrolling

后端 未结 12 737
时光说笑
时光说笑 2021-02-03 23:06

I have a _TableView with items , and I want to set automatic refresh,and I don\'t want it to scroll on refresh , lets say user scrolled 2 pages down , and the refre

12条回答
  •  名媛妹妹
    2021-02-03 23:22

    I am showing if only one row is being added. You can extend it to multiple rows.

        // dataArray is your data Source object
        [dataArray insertObject:name atIndex:0];
        CGPoint contentOffset = self.tableView.contentOffset;
        contentOffset.y += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        [self.tableView reloadData];
        [self.tableView setContentOffset:contentOffset];
    

    But for this to work you need to have defined - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath the method. Or else, you can directly give your tableview row height if it is constant.

提交回复
热议问题