gpt4 book ai didi

在 UISearchBar 下添加后 iOS Scope Bar 不出现

转载 作者:行者123 更新时间:2023-11-28 23:56:57 25 4
gpt4 key购买 nike

我在搜索栏下添加了范围栏。但是,范围栏不会出现。任何想法?请帮忙。

- (UISearchBar *)searchBar{
if (!_searchBar) {
_searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 24)];
[_searchBar setBackgroundImage:[UIImage imageNamed:@"ic_searchBar_bgImage"]];
[_searchBar sizeToFit];
[_searchBar setPlaceholder:@"Search"];
[_searchBar.layer setBorderWidth:0.5];
_searchBar.showsScopeBar = YES;
_searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"All", @"Near Me", @"Coming Soon", nil];

[_searchBar.layer setBorderColor:[UIColor colorWithRed:229.0/255 green:229.0/255 blue:229.0/255 alpha:1].CGColor];
[_searchBar setDelegate:self];
[_searchBar setKeyboardType:UIKeyboardTypeDefault];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"Bitter" size:14],
}];
}
return _searchBar;
}

已编辑:我在 Tableview 标题中添加了它。我怎样才能改变它以使其出现?

- (UITableView *)tableView{
if (!_tableView) {
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, kScreenWidth, kScreenHeight-49.0) style:UITableViewStylePlain];
[_tableView setDelegate:self];
[_tableView setDataSource:self];

_tableView.tableHeaderView=self.searchBar;

UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
[_tableView setTableFooterView:v];

}
return _tableView;
}

最佳答案

我尝试运行您的代码,范围栏对我来说显示正常。

因此,虽然我无法从代码中理解为什么它不应该出现,但我会在此处提供一些调试技巧,以帮助您了解哪些其他可能会导致此问题的错误。

当您的应用处于调试运行模式(iOS 模拟器)时,试试这个:

  • XCode -> 调试菜单 -> 查看调试
  • 按捕获 View 层次结构。
  • 它应该在左侧显示一个树结构,显示您的表格 View 。在右侧,它会显示您的观点的屏幕截图
  • 在左侧树中,查找 UISearchbar
  • 在其层次结构下,搜索类型为:_UISearchBarScopeBarBackground 的对象。紧随其后的是 UISegmentedControl,它具有与每个范围文本对应的段。

引用下图(这应该出现在您的范围层次结构中):

enter image description here

  • 如果 UISegmentedControl 在这里显示正常但在右侧不可见,请检查它是否被其他 View / TableView 本身隐藏。一些框架调整应该可以解决这个问题。

  • 如果 UISegmentedControl 本身没有出现在左侧,则您的问题似乎很严重。可能你的网点没有初始化,你可能想检查你的 TableView 是否正确初始化。在任何情况下,这种情况都不太可能发生,并且只有在您的模拟器屏幕上什么都看不到的情况下才有可能发生。

关于在 UISearchBar 下添加后 iOS Scope Bar 不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50965377/

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