DZNEmptyDataSet icon indicating copy to clipboard operation
DZNEmptyDataSet copied to clipboard

The empty view is shifted when changing the datasource

Open lucaspang opened this issue 9 years ago • 6 comments

I have one tableview with a tab to switch between 2 datasources, the first datasource have 10 items, the second datasource have no item.

the steps to reproduce the issue were:

  • scroll to the bottom(or any position) in the first datasource
  • switch to the second datasource, and reloadData
  • the empty view is shown and shifted down a lot

I have tried both custom view and basic title with no luck.

Please let me know if you need any more details. Thanks.

lucaspang avatar Apr 14 '16 09:04 lucaspang

Try using the implementation from https://github.com/dzenbot/DZNEmptyDataSet/pull/182 and let me know if this fixes it.

dzenbot avatar Apr 22 '16 07:04 dzenbot

Hello I have tested the fix, it should be fine for tableview that has no header(or contentInset Top), so I have to add the following code inside the fix to make it fit for general case: [self setContentOffset:CGPointMake(0, -self.contentInset.top)];

lucaspang avatar Apr 27 '16 05:04 lucaspang

Hi, I have same question with you. but my tableview is have a custom headerView. can you help me?

ldhios avatar Jun 30 '17 09:06 ldhios

@ldhios You have to implement verticalOffsetForEmptyDataSet of DZNEmptyDataSetSource.

Objective-C:

- (CGFloat) verticalOffsetForEmptyDataSet:(UIScrollView *) scrollView {
    return -self.tableView.tableHeaderView.frame.size.height/2.0f;
}

Swift:

func verticalOffset(forEmptyDataSet scrollView: UIScrollView!) -> CGFloat {
    guard let tableHeaderView = self.tableView.tableHeaderView else { return 0 }
    return tableHeaderView.frame.height/2
}

mathebox avatar Sep 13 '17 10:09 mathebox

@mathebox what about UICollectionView?

anirudhamahale avatar Jan 05 '22 07:01 anirudhamahale

@anirudhamahale Since it's already been 4 years, I can't really tell. Not sure how supplementary views will effect this. But I'm sure that there will be a way to account for the offset.

FYI: I personally have moved to using an own implementation for UITableView and UICollectionView.

mathebox avatar Jan 05 '22 14:01 mathebox