Question:
When I click on it, I find that only UICollectionViewCell is responding, and when I click somewhere else, I don’t respond to UITableViewCell’s click event.
Cause analysis:
First, analyze the event response chain: When your finger touches the screen, UIKit will generate an event (UIEvent) object and add it to the event queue, and then UIApplication will take it out of the event queue and distribute it first to UIWindow, and distribute it from UIWindow, Distribution depends on UIView’s two classification methods hitTest:withEvent: & pointInside:withEvent: and UIView’s userInteractionEnabled, Hidden and Alpha properties. When clicking anywhere else in the TableViewCell, the event is passed first to the UITableviewcell, and then in turn to the UICollectionView, UICollectionViewCell, or UICollectionReusableView, So that the last click didn’t respond. The response chain is shown below:
Solutions:
Intercepts UITableViewCell events. Implement the following method in the UITableViewCell, which tells the system that the event is handled by the UITableViewCell when the click is on the UICollectionView, It responds to the click event of the UITableViewCell.
– (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
/ / if you don’t can interact the transparency of the hidden | | 3 small any neglect not click
if(! Self. UserInteractionEnabled | | self. Hidden | | the self. The alpha < = 0.01) {
return nil;
}
UIView *view = [super hitTest:point withEvent:event];
if ([view isKindOfClass:[UICollectionView class]] ||
[view isKindOfClass:[HGOrderListMoreGoodsCollectionCell class]]) {
return self;
}
return view;
}