gpt4 book ai didi

ios - UIPopoverController 中的 UISearchBar 在点击时移动

转载 作者:行者123 更新时间:2023-11-28 22:23:26 29 4
gpt4 key购买 nike

我目前正在尝试在弹出窗口中放置一个 TableView 和搜索栏,但我遇到了一个非常奇怪的错误。每当我点击搜索栏时,取消按钮就会出现动画,搜索栏会立即缩小到状态栏的大小。

Normal State

When Selected

我试过使用 UIBarPosition 委托(delegate),但这也没有任何作用。我已经尝试了几乎所有我能想到的方法,所以我想我会寻求你的帮助。这是我在 UITableViewController 中用于将搜索栏添加到表格标题的代码:

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];

if (self)
{

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, popoverWidth, singleRowHeight)];
searchBar.delegate = self;
searchBar.showsScopeBar= YES;

searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
searchDisplayController.searchResultsTableView.rowHeight = singleRowHeight;
self.automaticallyAdjustsScrollViewInsets = NO;

self.tableView.tableHeaderView = searchBar;

return self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTop;
}

谢谢!

最佳答案

根据 Extra space above search bar when UISearchDisplayController is active

- (void)viewDidLoad {
[super viewDidLoad];

if ([self respondsToSelector:@selector(edgesForExtendedLayout:)]) { /// iOS 7 or above
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}

关于ios - UIPopoverController 中的 UISearchBar 在点击时移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19670373/

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