我看了很多回复,仍然无法弄清楚。我知道第一行有点奇怪,但它是因为它继承自一个将 headerview 设置为搜索栏的超类
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];