DZNEmptyDataSet
DZNEmptyDataSet copied to clipboard
The empty view is shifted when changing the datasource
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.
Try using the implementation from https://github.com/dzenbot/DZNEmptyDataSet/pull/182 and let me know if this fixes it.
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)];
Hi, I have same question with you. but my tableview is have a custom headerView. can you help me?
@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 what about UICollectionView?
@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.