[英]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
UIView2
的userInteractionEnabled
,可以在代碼中看到:
#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.