gpt4 book ai didi

objective-c - UISearchBar 最小样式与范围按钮错误?

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:33 25 4
gpt4 key购买 nike

当我将最小样式设置为搜索栏时出现错误。我的代码在这里:

- (void)viewDidLoad
{
sc = [[UISearchController alloc] initWithSearchResultsController:nil];
sc.searchResultsUpdater = self;
sc.delegate = self;
sc.dimsBackgroundDuringPresentation = NO;
sc.searchBar.delegate = self;
self.definesPresentationContext = YES;
[sc.searchBar setPlaceholder:@"Search"];
[sc.searchBar setSearchBarStyle:UISearchBarStyleMinimal];
[sc.searchBar sizeToFit];
[sc.searchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"item1",@"item2",@"item3", nil]];
sc.searchBar.delegate = self;
self.tableView.tableHeaderView = sc.searchBar;
}

结果(触摸内部之前):enter image description here

当我触摸搜索栏时,它的开始看起来很正常。其他搜索栏样式也能正常工作。

编辑

这样试过;示波器按钮像图片一样出现了第二秒,然后消失了。

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[sc.searchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"item1",@"item2",@"item3", nil]];
}

edit2

当我将 [sc.searchBar setShowsScopeBar:YES] 放入 viewDidLoad 方法时,我得到第三个版本(触摸前搜索栏下的项目):

enter image description here

触摸界面看起来又正常了:

enter image description here

最佳答案

Apple 关于 UISearchBarStyle 的文档:

This property can be used together with barStyle. The style UISearchBarStyleMinimal provides no default background color or image but will display one if customized as such.

因此,当您将 searchBarStyle 设置为 UISearchBarStyleMinimal 时,它会删除背景图像和颜色,因此它基本上是透明的。现在要显示 Scope Bar 按钮,您必须在设置标题之前将 showsScopeBar 属性设置为 YES。所以:

[sc.searchBar setShowsScopeBar:YES];
[sc.searchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"item1",@"item2",@"item3", nil]];

关于objective-c - UISearchBar 最小样式与范围按钮错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28142894/

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