gpt4 book ai didi

iOS 7 不显示导航栏中搜索栏的取消按钮

转载 作者:IT王子 更新时间:2023-10-29 08:05:24 26 4
gpt4 key购买 nike

在应该在 iOS 6 和 iOS 7 上运行的应用程序中,如果该应用程序在 iOS 7 上运行,则不再显示导航栏中嵌入的搜索栏的取消按钮。在 iOS 6 上,它有效。

搜索栏位于导航栏的标题 View 中,如果搜索栏成为第一响应者,则应显示取消按钮:

iOS 7

enter image description here

iOS 6

enter image description here

在一个孤立的测试用例中,代码非常简单:

@interface MyViewController : UITableViewController<UISearchBarDelegate>

@property (nonatomic) IBOutlet UISearchBar* searchBar;

@end


@implementation MyViewController

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.titleView = self.searchBar;
}

- (void) searchBarTextDidBeginEditing: (UISearchBar*) searchBar {
[searchBar setShowsCancelButton: YES animated: YES];
}

@end

这是我在文档中遗漏的 iOS 7 中的故意更改吗?如果是,应该选择什么?

如果不是,是我的代码有误吗?

最佳答案

看起来你做的一切都是正确的,但显然 Apple 已经改变了 iOS 7 中的一些东西。According to this SO question在 iOS 7 中,取消按钮不会出现在嵌入 UINavigationBarUISearchBar 上。

根据developer documentation , showsCancelButton 属性的效果可能与 setShowsCancelButton:Animated 方法略有不同。尝试这样做:

searchBar.showsCancelButton = YES;
[searchBar setShowsCancelButton:YES animated:YES];

我不确定这是否会产生任何影响。您也可以尝试将代码放在不同的委托(delegate)方法中:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar; // return NO to not become first responder
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; // called when text starts editing

您可能还想查看 iOS 7 changelog .看起来 Apple 在添加到 UINavigationBar 时改变了行为或 UISearchDisplayController/UISearchBar。查看 UIKit 部分下的最后一个要点(虽然不清楚到底发生了什么变化)。


您可能还想尝试使用 UISerachDisplayController。可能更简单的方法是将 UISearchBar 嵌入到 UITableView 的 header 中。

关于iOS 7 不显示导航栏中搜索栏的取消按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19068435/

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