dzenbot / DZNEmptyDataSet

A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display
https://www.cocoacontrols.com/controls/dznemptydataset
MIT License
12.09k stars 1.73k forks source link

the custom view cannot respond to the click event. I modify a method work as well #404

Open yanyanforest opened 6 years ago

yanyanforest commented 6 years ago

I find that the custom view for delegate method - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView... reasons:as I think class DZNEmptyDataSetView implements method - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event .it wirte this:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitView = [super hitTest:point withEvent:event];

    // Return any UIControl instance such as buttons, segmented controls, switches, etc.
    if ([hitView isKindOfClass:[UIControl class]]) {
        return hitView;
    }

    // Return either the contentView or customView
    if ([hitView isEqual:_contentView] || [hitView isEqual:_customView]) {
        return hitView;
    }

    return nil;
}

then no any response, so I modify this method add if statement,

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitView = [super hitTest:point withEvent:event];

    // Return any UIControl instance such as buttons, segmented controls, switches, etc.
    if ([hitView isKindOfClass:[UIControl class]]) {
        return hitView;
    }

    // Return either the contentView or customView
    if ([hitView isEqual:_contentView] || [hitView isEqual:_customView]) {
        return hitView;
    }
    if ([hitView isKindOfClass:[DZNEmptyDataSetView class]]) {
        return hitView;
    }
    return nil;
}

so has response,works as well

kirinzer commented 5 years ago

it is work for me, thx!

kirinzer commented 5 years ago

I find the really reason, customView lost a constraints in the below function. - (void)setupConstraints I suggest u change the version to v1.6.1, everything is ok!

yanyanforest commented 5 years ago

@kirinzer how you change the function - (void)setupConstraints?

I do like this in this method 'if (_customView) { CGFloat height = _customView.bounds.size.height; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[customView]|" options:0 metrics:nil views:@{@"customView":_customView}]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[customView(==height)]|" options:0 metrics:@{@"height":@(height)} views:@{@"customView":_customView}]]; }'. about you?