gpt4 book ai didi

ios - 为什么 UIButton 不响应触摸?

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:40 25 4
gpt4 key购买 nike

我看了很多回复,还是想不通。我知道第一行有点奇怪,但这是因为它继承自将标题 View 设置为搜索栏的父类(super class)

searchBar = (UISearchBar *)self.tableView.tableHeaderView;
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, -100, self.view.frame.size.width, 100)];
label.text = @"AAAA";
[searchBar addSubview:label];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, -60, 160.0, 40.0);

searchBar.exclusiveTouch = NO;
searchBar.userInteractionEnabled = NO;
label.userInteractionEnabled = NO;
button.userInteractionEnabled = YES;
[searchBar insertSubview:button atIndex:3];

最佳答案

userInteractionEnabled 在父 View 上设置为 NO 将级联到所有 subview 。因此,您的 UIButton 实例将显示为无响应,因为 searchBar 已禁用。

关于ios - 为什么 UIButton 不响应触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com