gpt4 book ai didi

ios - 如果我更改约束,Xcode 搜索栏不在表标题 View 中

转载 作者:行者123 更新时间:2023-11-29 01:17:38 25 4
gpt4 key购买 nike

我想在表格 View 的顶部制作一个搜索栏我想在单击按钮时更改 TableView 的位置。

(我用这段代码制作了搜索栏)

searchController = UISearchController(searchResultsController: nil)   
table.tableHeaderView = searchController.searchBar

所以我改变了约束并且它移动了。

但问题是如果搜索处于事件状态,搜索栏不会跟随表格 View 。如果我点击取消按钮,它就会随之而来。

为什么会这样?有什么解决办法吗?

最佳答案

您是如何创建搜索栏的?我正在使用它并像这样创建:

Search Bar example

我已将 Table View 添加到我的场景中,并向其添加了 Search Bar 和 Search Display Controller。我还在我的 viewDidLoad 中添加了以下代码:

- (void)viewDidLoad {
[super viewDidLoad];

[self.processTableView setDelegate:self];
[self.processTableView setDataSource:self];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.processTableView.tableHeaderView = self.searchController.searchBar;

self.definesPresentationContext = YES;
}

像这样使用它,我得到了搜索栏的预期行为。这是您想要实现的目标吗?

enter image description here

关于ios - 如果我更改约束,Xcode 搜索栏不在表标题 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975394/

25 4 0