-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Gestures not reaching custom view in iOS7 when tableview has a background view #47
Comments
That makes sense. So instead of |
Just ran into the same issue. Unfortunately, if the Not sure how to best approach this without it being brittle towards the future :/ |
In that case, we must make sure it gets inserted at the latest index, right?
|
I would do that, but your original code specifically mentions inserting the Inserting at the last index is the same as just doing A hacky workaround that doesn't look for a specific classname would be something like this: 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) {
__block NSUInteger *highestIndexOfTableViewFillingSubview = 0;
[self.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
if (CGRectEqualToRect(subview.bounds, self.frame)) {
highestIndexOfTableViewFillingSubview = idx;
}
}];
[self insertSubview:view atIndex:highestIndexOfTableViewFillingSubview+1];
}
else {
[self addSubview:view];
}
} But I don't really love that approach either. Edit: |
Something like this: 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) {
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 &&
floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
// annoying hack to work around an iOS 7 issue
__block NSUInteger *highestIndexOfTableViewFillingSubview = 0;
[self.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
if (CGRectEqualToRect(subview.bounds, self.frame)) {
highestIndexOfTableViewFillingSubview = idx;
}
}];
[self insertSubview:view atIndex:highestIndexOfTableViewFillingSubview+1];
}
else {
[self insertSubview:view atIndex:1];
}
}
else {
[self addSubview:view];
}
} |
This fixes dzenbot#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.
Hi, here's curly one.
It appears that if you insert the empty view beneath the UITableViewWrapperView in the tableview's hierarchy, gestures don't work in iOS7.
Normally it's fine, since inserting the empty view at index 1 puts it above this view (UITableViewWrapperView view is usually at index 0)
But if you've set a background view for your tableview, the background view is at index 0 and the UITableViewWrapperView is at index 1. Thus the empty view is inserted beneath the UITableViewWrapperView view.
This is only a problem in iOS7. In iOS8 inserting the empty view beneath the UITableViewWrapperView view doesn't seem to matter, gestures still work.
Here's my solution:
I can submit a pull request if you think the above is not crazy.
The text was updated successfully, but these errors were encountered: