我在xcode
版本6.1中工作。我只是将UISearchBar
拖放到我的UIViewController
中......现在我只是为iPad设备复制并粘贴了这个storyboard
..但对于iPhone设备,我可以看到取消按钮,但对于Ipad设备,取消按钮没有出现..
以下是代码
[searchBar setPlaceholder:AMLocalizedString(@"Search people", nil)];
id barButtonAppearanceInSearchBar = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[barButtonAppearanceInSearchBar setTitle:AMLocalizedString(@"Cancel",nil)];
任何人都可以帮助我!!!!!
答案 0 :(得分:0)
尝试使用rightBarButtonItem
答案 1 :(得分:-1)
我知道您正在尝试将UISearchBar嵌入NavigationBar / Toolbar中;如果是这样,这是一个以编程方式执行此操作的解决方案: iOS7 when UIsearchbar added in UINavigationBar not showing cancel button
UISearchBar *searchBar = [UISearchBar new];
searchBar.showsCancelButton = YES;
[searchBar sizeToFit];
UIView *barWrapper = [[UIView alloc]initWithFrame:searchBar.bounds];
[barWrapper addSubview:searchBar];
self.navigationItem.titleView = barWrapper;