From 10d3d74f87931b5995d011f84a89312f54c4abce Mon Sep 17 00:00:00 2001 From: Bart Vandendriessche Date: Wed, 4 Feb 2015 10:52:08 +0100 Subject: [PATCH] Fix an issue that causes the button to not receive touches on iOS 7 This commit introduces a `indexForEmptyDataSetView` method to encapsulate the logic that figures out where to insert the `DZNEmptyDataSetView` in the `UIScrollView` subviews hierarchy. Figuring out the proper index is moderately complex because it needs some decision making based on the `UIScrollView`s actual class and the current iOS version. --- Source/UIScrollView+EmptyDataSet.m | 34 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index 7795bed2..add54a10 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -362,14 +362,7 @@ - (void)dzn_reloadEmptyDataSet UIView *customView = [self dzn_customView]; if (!view.superview) { - - // Send the view to back, in case a header and/or footer is present - if ([self isKindOfClass:[UITableView class]] && self.subviews.count > 1) { - [self insertSubview:view atIndex:1]; - } - else { - [self addSubview:view]; - } + [self insertSubview:view atIndex:[self indexForEmptyDataSetView]]; } // Moves all its subviews @@ -393,7 +386,7 @@ - (void)dzn_reloadEmptyDataSet [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:0] forState:0]; [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:1] forState:1]; [view.button setUserInteractionEnabled:[self dzn_isTouchAllowed]]; - + // Configure spacing view.verticalSpace = [self dzn_verticalSpace]; } @@ -416,6 +409,29 @@ - (void)dzn_reloadEmptyDataSet } } +- (NSInteger)indexForEmptyDataSetView { + // Send the view to back, in case a header and/or footer is present + if ([self isKindOfClass:[UITableView class]] && self.subviews.count > 1) { + if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 && + floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { + // annoying hack to work around an iOS 7 issue + __block NSUInteger *highestIndexOfTableViewFittingSubview = 0; + [self.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { + if (CGRectEqualToRect(subview.bounds, self.frame)) { + highestIndexOfTableViewFittingSubview = idx; + } + }]; + return highestIndexOfTableViewFittingSubview+1; + } + else { + return 1; + } + } + else { + return self.subviews.count; + } +} + - (void)dzn_invalidate { // Notifies that the empty dataset view will disappear