Ios UIVIew中嵌入的UIButton不负责

Ios UIVIew中嵌入的UIButton不负责,ios,objective-c,uitableview,uiview,uibutton,Ios,Objective C,Uitableview,Uiview,Uibutton,我有个问题 我创建了6个ui按钮将它们放入ui视图1 然后将UIView1放入另一个UIView2 然后将UIView2返回为UITableView.tableHeaderView 现在的问题是当我触摸按钮时 无责任 这里有一些信息 1. ui按钮UIView1UIView2这些按钮是什么 2017-06-04 16:26:40.014 LOLHelper[8590:223132] BUT frame is :8.000000 8.000000 70.500000 18.000000 2

我有个问题

我创建了6个
ui按钮
将它们放入
ui视图1

然后将
UIView1
放入另一个
UIView2

然后将
UIView2
返回为
UITableView.tableHeaderView

现在的问题是当我触摸按钮时

无责任

这里有一些信息 1.
ui按钮
UIView1
UIView2
这些按钮是什么

    2017-06-04 16:26:40.014 LOLHelper[8590:223132] BUT frame is :8.000000 8.000000 70.500000 18.000000
2017-06-04 16:26:40.014 LOLHelper[8590:223132] BUT frame is :86.500000 8.000000 71.000000 18.000000
2017-06-04 16:26:40.014 LOLHelper[8590:223132] BUT frame is :165.500000 8.000000 70.500000 18.000000
2017-06-04 16:26:40.015 LOLHelper[8590:223132] BUT frame is :244.000000 8.000000 70.500000 18.000000
2017-06-04 16:26:40.015 LOLHelper[8590:223132] BUT frame is :322.500000 8.000000 71.000000 18.000000
2017-06-04 16:26:40.015 LOLHelper[8590:223132] BUT frame is :401.500000 8.000000 70.500000 18.000000
2017-06-04 16:26:40.015 LOLHelper[8590:223132] SubView frame is: :-3.000000 0.000000 480.000000 20.000000
2017-06-04 16:26:40.015 LOLHelper[8590:223132] headerView frame is: :0.000000 0.000000 320.000000 20.000000
2.我打开
ui按钮的
userInteractionEnabled
UIView1
UIView2
,你可以在代码中看到:

    #import "TableViewDataSource.h"


@implementation TableViewDataSource

@synthesize tableView;
@synthesize tableCell;
@synthesize LHfetchedResultsController;
@synthesize numberOfRows;
@synthesize dataTemp;
@synthesize paused;
@synthesize type;
@synthesize imgAche;
@synthesize cellHeight;
@synthesize subHeaderViewFrame;

-(id)initWithTableView:(UITableView *) tableView
{
    self = [super init];
    if (self) {
        self.tableView = tableView;
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.tableHeaderView = [self setHeaderView];
    }
    return self;
}
-(UIView *)setHeaderView
{
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    UIView * container = [[UIView alloc] init];
    container.frame = CGRectMake(0, 0, screenSize.width, 20);
    container.userInteractionEnabled = YES;

    UIView * headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, screenSize.width*1.5, 20);
    headerView.tag = 01;
    headerView.userInteractionEnabled = YES;
    [container addSubview:headerView];
    for (int i = 1; i < 7; i++) {
        UIButton * button = [[UIButton alloc] init];
        button.tag = i+10;
        button.titleLabel.font = [UIFont boldSystemFontOfSize:12];
        [button setTitle:[NSString stringWithFormat:@"but0%d",i] forState:UIControlStateNormal];
        [button setTitle:[NSString stringWithFormat:@"but0%d s",i] forState:UIControlStateSelected];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.translatesAutoresizingMaskIntoConstraints = NO;
        [button setTitleColor:[UIColor brownColor] forState:UIControlStateSelected];
        button.enabled = YES;
        button.userInteractionEnabled = YES;
        [headerView addSubview:button];
    }
    UIButton *button01 = [headerView viewWithTag:11];
    UIButton *button02 = [headerView viewWithTag:12];
    UIButton *button03 = [headerView viewWithTag:13];
    UIButton *button04 = [headerView viewWithTag:14];
    UIButton *button05 = [headerView viewWithTag:15];
    UIButton *button06 = [headerView viewWithTag:16];

    NSDictionary * views = NSDictionaryOfVariableBindings(button01,button02,button03,button04,button05,button06);
    NSString * vflV1 = @"V:|-1-[button01]-1-|";
    NSString * vflV2 = @"V:|-1-[button02]-1-|";
    NSString * vflV3 = @"V:|-1-[button03]-1-|";
    NSString * vflV4 = @"V:|-1-[button04]-1-|";
    NSString * vflV5 = @"V:|-1-[button05]-1-|";
    NSString * vflV6 = @"V:|-1-[button06]-1-|";
    NSString * vflH1 = @"H:|-[button01]-[button02(==button01)]-[button03(==button01)]-[button04(==button01)]-[button05(==button01)]-[button06(==button01)]-|";

    NSArray * constraintsV1 = [NSLayoutConstraint constraintsWithVisualFormat:vflV1 options:0 metrics:NULL views:views];
    NSArray * constraintsV2 = [NSLayoutConstraint constraintsWithVisualFormat:vflV2 options:0 metrics:NULL views:views];
    NSArray * constraintsV3 = [NSLayoutConstraint constraintsWithVisualFormat:vflV3 options:0 metrics:NULL views:views];
    NSArray * constraintsV4 = [NSLayoutConstraint constraintsWithVisualFormat:vflV4 options:0 metrics:NULL views:views];
    NSArray * constraintsV5 = [NSLayoutConstraint constraintsWithVisualFormat:vflV5 options:0 metrics:NULL views:views];
    NSArray * constraintsV6 = [NSLayoutConstraint constraintsWithVisualFormat:vflV6 options:0 metrics:NULL views:views];
    NSArray * constraintsH1 = [NSLayoutConstraint constraintsWithVisualFormat:vflH1 options:0 metrics:NULL views:views];

    [headerView addConstraints:constraintsV1];
    [headerView addConstraints:constraintsV2];
    [headerView addConstraints:constraintsV3];
    [headerView addConstraints:constraintsV4];
    [headerView addConstraints:constraintsV5];
    [headerView addConstraints:constraintsV6];
    [headerView addConstraints:constraintsH1];

    return container;
}
#导入“TableViewDataSource.h”
@TableViewDataSource的实现
@综合桌面视图;
@合成表细胞;
@合成lhedresults控制器;
@合成行数;
@合成数据温度;
@合成暂停;
@综合型;
@合成imgAche;
@综合细胞高度;
@合成子标题服务框架;
-(id)initWithTableView:(UITableView*)tableView
{
self=[super init];
如果(自我){
self.tableView=tableView;
self.tableView.dataSource=self;
self.tableView.delegate=self;
self.tableView.tableHeaderView=[self-setHeaderView];
}
回归自我;
}
-(UIView*)setHeaderView
{
CGSize screenSize=[UIScreen mainScreen].bounds.size;
UIView*容器=[[UIView alloc]init];
container.frame=CGRectMake(0,0,screenSize.width,20);
container.userInteractionEnabled=是;
UIView*headerView=[[UIView alloc]init];
headerView.frame=CGRectMake(0,0,屏幕大小.宽度*1.5,20);
headerView.tag=01;
headerView.userInteractionEnabled=是;
[容器添加子视图:headerView];
对于(int i=1;i<7;i++){
UIButton*按钮=[[UIButton alloc]init];
button.tag=i+10;
button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
[按钮设置标题:[NSString stringWithFormat:@“but0%d”,i]用于状态:UIControlStateNormal];
[按钮集标题:[NSString stringWithFormat:@“but0%d s”,i]用于状态:UIControlStateSelected];
[按钮设置标题颜色:[UIColor blackColor]用于状态:UIControlStateNormal];
button.translatesAutoresizingMaskIntoConstraints=否;
[按钮设置标题颜色:[UIColor brownColor]用于状态:UIControlStateSelected];
button.enabled=是;
button.userInteractionEnabled=是;
[头视图添加子视图:按钮];
}
UIButton*button01=[headerView视图带标签:11];
UIButton*button02=[headerView视图带标签:12];
UIButton*button03=[headerView视图带标签:13];
UIButton*button04=[headerView视图带标签:14];
UIButton*button05=[headerView视图带标签:15];
UIButton*button06=[headerView视图带标签:16];
NSDictionary*视图=NSDictionaryOfVariableBindings(按钮01、按钮02、按钮03、按钮04、按钮05、按钮06);
NSString*vflV1=@“V:|-1-[button01]-1-|”;
NSString*vflV2=@“V:|-1-[button02]-1-|”;
NSString*vflV3=@“V:|-1-[button03]-1-|”;
NSString*vflV4=@“V:|-1-[button04]-1-|”;
NSString*vflV5=@“V:|-1-[button05]-1-|”;
NSString*vflV6=@“V:|-1-[button06]-1-|”;
NSString*vflH1=@“H:|-[button01]-[button02(=button01)]-[button03(=button01)]-[button04(=button01)]-[button05(=button01)]-[button06(=button01)]-|”;
NSArray*constraintsV1=[NSLayoutConstraintsWithVisualFormat:vflV1选项:0度量:空视图:视图];
NSArray*constraintsV2=[NSLayoutConstraintsWithVisualFormat:vflV2选项:0度量:空视图:视图];
NSArray*constraintsV3=[NSLayoutConstraintsWithVisualFormat:vflV3选项:0指标:空视图:视图];
NSArray*constraintsV4=[NSLayoutConstraintsWithVisualFormat:vflV4选项:0指标:空视图:视图];
NSArray*constraintsV5=[NSLayoutConstraintsWithVisualFormat:vflV5选项:0指标:空视图:视图];
NSArray*constraintsV6=[NSLayoutConstraintsWithVisualFormat:vflV6选项:0指标:空视图:视图];
NSArray*constraintsH1=[NSLayoutConstraintsWithVisualFormat:vflH1选项:0度量:空视图:视图];
[headerView addConstraints:constraintsV1];
[headerView addConstraints:constraintsV2];
[headerView addConstraints:constraintsV3];
[headerView addConstraints:constraintsV4];
[headerView addConstraints:constraintsV5];
[headerView addConstraints:constraintsV6];
[headerView addConstraints:constraintsH1];
返回容器;
}
我还没有找到原因

有人能帮我吗

我还向
UIView2

谢谢你们

谢谢你们 我找到了解决办法 原因是

[按钮添加目标:空操作:@选择器(单击:)forControlEvents:UIControlEventTouchUpInside]
我将target设置为NULL,并在同一个文件中写入
click:
,但实际上我是从主控制器获取表的,所以当我单击按钮时,xcode将在主控制器中找到
click:
,然后找不到,因此没有责任。 在我设置目标自我或写入
后,单击主控制器中的:

它工作

可能有一个视图覆盖了你的tableview的标题部分,检查它。我的结构如下:
self.tableview.tableHeaderView
包含一个
UIView
,然后
UIView
包含6个
UIButtons
,所有关于这些的代码都在那里,我可以在代码中成功地获得按钮,所以我不确定是否有另一个我没有注意到的视图,你能告诉我它可能是什么视图吗?是否有一个视图包含tableView?该容器视图中还有其他视图吗?如果不将
uiwipegesturecognizer
添加到
UIView2
中,可以点击按钮吗?如果是这样,那么您已经发现了问题。@YunCHEN我没有在容器视图中添加另一个
UIView
,而tableView是insert main
ViewContro