繁体   English   中英

UIButton内嵌的UIButton概不负责

[英]UIButton embeded in UIVIew no responsible

我有个问题

我创建了6个UIButtons将它们放在UIView1

然后将UIView1放入另一个UIView2

然后将UIView2作为UITableView.tableHeaderView返回

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

没有责任

这里是一些信息1 UIButtons UIView1 UIView2 fremes是这些

    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.我打开UIButtons UIView1 UIView2userInteractionEnabled ,可以在代码中看到:

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

我没有找到原因

有人可以帮助我吗?

我还将一些UISwipeGestureRecognizer添加到UIView2

感谢你

谢谢你们,我得到解决方案的原因是: [button addTarget:NULL action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; 我将目标设置为NULL,并在同一文件中写入click: ,但实际上我是从主控制器获取表的,所以当我单击按钮时,xcode会在主控制器中找到click: ,然后找不到,所以不承担任何责任。 在我设置目标自我或click:在主控制器中工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM