From 9b259d949d5d57b582988da8e606e1d52b9601db Mon Sep 17 00:00:00 2001 From: Bart Vandendriessche Date: Tue, 25 Aug 2015 11:16:41 +0200 Subject: [PATCH] Fixes gestures not passing through UITableViewWrapperView on iOS 7 This fixes #47 In a nutshell, this pull request toggles `UITableViewWrapperView`'s `userInteractionEnabled` property off or on when the `emptyDataSetView` appears or disappears. The main concern here I suppose is the check for "UITableViewWrapperView" since that is a private API. This call is guarded by a version check, so shouldn't break in future releases, but I'm not sure if checking for this class could cause an app to be rejected. For what it's worth, validating an Archive containing this code didn't cause any private API flags to be raised. --- Source/UIScrollView+EmptyDataSet.m | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index d3e2b4ea..1522b79f 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -36,6 +36,30 @@ - (void)prepareForReuse; @end +@interface UITableView (DZNiOS7TableViewWrapperView) + +- (UIView *)dzn_tableViewWrapperView; + +@end + +@implementation UITableView (DZNiOS7TableViewWrapperView) + +- (UIView *)dzn_tableViewWrapperView { + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1 && + floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 && + [self isKindOfClass:[UITableView class]]) { + for (UIView *subview in [self subviews]) { + if ([subview isKindOfClass:NSClassFromString(@"UITableViewWrapperView")]) { + return subview; + } + } + } + + return nil; +} + +@end + #pragma mark - UIScrollView+EmptyDataSet @@ -287,6 +311,10 @@ - (void)dzn_willAppear - (void)dzn_didAppear { + if ([self isKindOfClass:[UITableView class]]) { + [(UITableView *)self dzn_tableViewWrapperView].userInteractionEnabled = NO; + } + if (self.emptyDataSetDelegate && [self.emptyDataSetDelegate respondsToSelector:@selector(emptyDataSetDidAppear:)]) { [self.emptyDataSetDelegate emptyDataSetDidAppear:self]; } @@ -301,6 +329,10 @@ - (void)dzn_willDisappear - (void)dzn_didDisappear { + if ([self isKindOfClass:[UITableView class]]) { + [(UITableView *)self dzn_tableViewWrapperView].userInteractionEnabled = YES; + } + if (self.emptyDataSetDelegate && [self.emptyDataSetDelegate respondsToSelector:@selector(emptyDataSetDidDisappear:)]) { [self.emptyDataSetDelegate emptyDataSetDidDisappear:self]; }