Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iTableView backgroundView中控件的iOS 7.0用户交互已禁用_Ios_Uitableview_Ios7 - Fatal编程技术网

iTableView backgroundView中控件的iOS 7.0用户交互已禁用

iTableView backgroundView中控件的iOS 7.0用户交互已禁用,ios,uitableview,ios7,Ios,Uitableview,Ios7,我已将自定义视图设置为UITableview的背景视图。当tableview为空时,该视图用于执行某些操作。 我在视图上有一些按钮&每个按钮都有一个动作 对于iOS7,在backgroundView中的按钮上设置的操作不会被调用。这似乎在backgroundView上禁用了交互 这是iOS 7的一个问题。还有其他人面临同样的问题吗?首先,将可触摸项目添加到tableView背景视图是一种糟糕的方法。 其次,我不确定我的解决方案是否适用于你的情况 尝试在BackgroundView类中实现以下方法

我已将自定义视图设置为UITableview的背景视图。当tableview为空时,该视图用于执行某些操作。
我在视图上有一些按钮&每个按钮都有一个动作
对于iOS<7,在背景视图内的按钮上正确调用操作 但是对于iOS>7,在backgroundView中的按钮上设置的操作不会被调用。这似乎在backgroundView上禁用了交互

这是iOS 7的一个问题。还有其他人面临同样的问题吗?

首先,将可触摸项目添加到tableView背景视图是一种糟糕的方法。 其次,我不确定我的解决方案是否适用于你的情况

尝试在BackgroundView类中实现以下方法:

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
    UIView* hitView = [super hitTest:point withEvent:event];
    if (hitView != nil)
    {
        [self.superview bringSubviewToFront:self];
    }
    return hitView;
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
{
    CGRect rect = self.bounds;
    BOOL isInside = CGRectContainsPoint(rect, point);
    if(!isInside)
    {
        for (UIView *view in self.subviews)
        {
            isInside = CGRectContainsPoint(view.frame, point);
            if(isInside)
                break;
        }
    }
    return isInside;
}
通过覆盖这些方法,您可以使backgroundView的所有子视图以及backgroundView本身都具有触敏性

干杯


更新:


对不起,这不起作用。BackgroundView位于带有单元格的视图后面,因此它不会收到触摸。

如我在评论中所述,这是iOS7中的一个已知问题,请参阅雷达()

但我的解决方案或解决方法是在表的顶部实现一个“代理”视图,该视图提供了一个协议,将命中测试转发给实现该协议的代理

EventFixBackrgoundView.h

@protocol EventFixBackrgoundViewDelegate <NSObject>
- (UIView *)eventFixHitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end

@interface EventFixBackrgoundView:UIView
@property (nonatomic, weak) id <EventFixBackrgoundViewDelegate> delegate;
@end

背景视图前面有一个截取交互的
UITableViewWrapperView
视图。你不能仅仅使用表的
tableHeaderView
属性来代替吗?

我认为,这是一个“已知问题”,请参见此处的雷达:使用tableHeaderView可以防止对视图底部使用约束来布局内容,例如,在空表中垂直居中。
#import "EventFixBackrgoundView.h"
@implementation EventFixBackrgoundView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(eventFixHitTest:withEvent:)])
    {
        return [self.delegate eventFixHitTest:point withEvent:event];
    }
    return [super hitTest:point withEvent:event];
}
@end