我在 UINavigationBar 上方添加 UISearchBar 并设置 UIsearchbar showsCancelButton YES,在 iOS6 中工作正常,但在 iOS7 中不显示取消按钮。我使用了下面的代码片段
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 600, 44)];
searchBar.showsCancelButton = YES;
searchBar.translucent = NO;
[searchBar setTintColor:[UIColor redColor]];
searchBar.backgroundColor = [UIColor yellowColor];
[self.navigationController.navigationBar addSubview:searchBar];