Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

The empty view is shifted when changing the datasource #241

Open
lucaspang opened this issue Apr 14, 2016 · 6 comments
Open

The empty view is shifted when changing the datasource #241

lucaspang opened this issue Apr 14, 2016 · 6 comments

Comments

@lucaspang
Copy link

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.

@dzenbot
Copy link
Owner

dzenbot commented Apr 22, 2016

Try using the implementation from #182 and let me know if this fixes it.

@lucaspang
Copy link
Author

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)];

@ldhios
Copy link

ldhios commented Jun 30, 2017

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

@mathebox
Copy link

@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
}

@anirudhamahale
Copy link

@mathebox what about UICollectionView?

@mathebox
Copy link

mathebox commented Jan 5, 2022

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants