2017-06-04 55 views
0

我有一个问题的UIButton中的UIView内嵌不负责

我创建6 UIButtons把它们放在一个UIView1

然后把UIView1到另一个UIView2

然后返回UIView2UITableView.tableHeaderView

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

没有责任心

这里是一些信息 1. UIButtonsUIView1UIView2 fremes是对的userInteractionEnabledUIButtonsUIView1UIView2这些

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.I反过来,美国可以在代码中看到:

#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; 
} 

我还没有找到原因

任何人都可以帮助我?

我还添加一些UISwipeGestureRecognizerUIView2

感谢ü

+0

可能有一个视图覆盖了你的tableview的头部分,请检查它。 –

+0

我的结构是这样的:'self.tableView.tableHeaderView'包含'UIView',然后'UIView'包含6个'UIButtons',并且关于这些的所有代码都在那里,我可以在代码中成功获取按钮,所以我不确定是否有另一种我没有注意到的观点,你能告诉我它有什么看法。 –

+0

有没有包含tableView的视图?在容器视图中还有其他视图吗? –

回答

0

谢谢能跟大家 我得到了解决 原因是 [button addTarget:NULL action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; 我设定的目标为NULL,并写入click:在同一个文件,但实际上我从主控制器得到表,所以当我点击按钮时,xcode会在主控制器中找到click:,然后找不到,所以没有责任。 我设定了目标自我或在主控制器中写入click: 它的工作原理