DZNEmptyDataSet icon indicating copy to clipboard operation
DZNEmptyDataSet copied to clipboard

When I scroll up about 2~3 cell, the empty image was going down

Open Yiiff opened this issue 7 years ago • 6 comments

Hi, I used this was fine, but since this version, my app has a new HomePage, so this empty image has a problem, I can't describe it problem clearly, so I make a video, here is the link

What can I do for this, I used same code, but It work like what you can see from the video.

// I user the delegate.
// but I set automaticallyAdjustsScrollViewInsets to NO!!!!

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 104) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor colorWithHexString:@"F6F6F6" alpha:1.0];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        [_tableView registerNib:[NewOrderListCell nib]
         forCellReuseIdentifier:Identifier];
        _tableView.estimatedRowHeight = 185.0f;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedSectionHeaderHeight = 333.0;
        _tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
        _tableView.estimatedSectionFooterHeight = 35.0;
        _tableView.sectionFooterHeight = UITableViewAutomaticDimension;
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
        
    }
    return _tableView;
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return -170;
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIImage imageNamed:@"icon_daiqiang_no-order"];
}
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString *text = @"订单正在来的路上\n下拉可刷新";
    
    NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
    paragraph.alignment = NSTextAlignmentCenter;
    
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f],
                                 NSForegroundColorAttributeName: [UIColor lightGrayColor],
                                 NSParagraphStyleAttributeName: paragraph};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
   
   // I can't scroll more data to show filterMenuView, so I add this line.
    if (!self.orderIdArray.count && !self.dataSource.count) {
        self.tableView.contentSize =CGSizeMake(0,SCREEN_HEIGHT + 70);
    }

  // about show filterMenuView
    if (self.marginTop != scrollView.contentInset.top) {
        self.marginTop = scrollView.contentInset.top;
    }
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat newoffsetY = offsetY + self.marginTop;
    if (newoffsetY >= 0 && newoffsetY <= 180) {
        self.filterMenuView.hidden = YES;
        [self.filterMenuView dismissPopView];
    } else if (newoffsetY > 180){
        if (self.aActNumber.integerValue == 2039) {
            self.filterMenuView.hidden = YES;
        } else {
            self.filterMenuView.hidden = NO;
        }
    } else{
        self.filterMenuView.hidden = YES;
        [self.filterMenuView dismissPopView];
    }
}

Yiiff avatar May 24 '17 14:05 Yiiff

If the link is failed, you can download it

Yiiff avatar May 24 '17 15:05 Yiiff

亲你怎么解决的?

yangzheng006 avatar Jul 10 '17 07:07 yangzheng006

I am seeing the same issue. If the table view's data set becomes empty when you are at the top of the table, the DZNEmptyDataSet view displays correctly. If you are scrolled down partway through the table when the dataset becomes empty, then the DZNEmptyDataSet view is placed further down the screen from where it should be - potentially offscreen.

fiannaca avatar Jul 12 '17 23:07 fiannaca

This issue was caused by the contentSize of tableView has been modified before dzn_reloadEmptyDataSet,I do like this to avoid this issue:

__weak __typeof(self)weakSelf = self;
[RACObserve(weakSelf.viewModel, arrRecords) subscribeNext:^(id  _Nullable x) {
    if (weakSelf.viewModel.arrRecords.count == 0) {
        weakSelf.tableView.contentSize = weakSelf.tableView.bounds.size;
    }
    [weakSelf.tableView reloadData];
}];

LucisBaoshg avatar Jul 17 '17 03:07 LucisBaoshg

I encountered the same issue and found a solution from #205. Try to setContentOffset to CGPoint.zero before reloadData of tableView

self.tableView.setContentOffset(CGPoint.zero, animated:false) 
self.tableView.reloadData()

allenhuang avatar Oct 08 '17 13:10 allenhuang

I reset scrollView's contentSize to solve my problem.

func emptyDataSetShouldDisplay(_ scrollView: UIScrollView!) -> Bool {
    scrollView.contentSize.height = scrollView.bounds.size.height
}

nogeo avatar May 28 '20 04:05 nogeo