我目前正在尝试为应用程序实现搜索功能。目标是在不同的视图控制器中显示搜索结果。我的意思确切地说是这样的:
UISearchController(searchResultsController: myCustomViewControllerHere)
我在教程中找到的所有答案都使用当前视图控制器和数据作为显示结果的视图控制器,如下所示:
UISearchController(searchResultsController: nil)
有人可以帮忙解决如何做到这一点吗?我链接了一个教程,它显示了同一 VC 上的结果
我的导航栏中有一个UiSearchbar.SearchBar风格很小.我在iOS 8上,使用SearchController(没有SearchDisplayController)和Swift.
我想将占位符和图标颜色设置为白色.这可能吗?到目前为止我发现的所有内容似乎都已过时,或者作者不确定此代码是否会被Apple批准.
我想摆脱取消按钮,但当我尝试这个:
searchController.searchBar.showsCancelButton = false
在viewDidLoad中,取消按钮仍然显示.
我必须说,我正在以编程方式创建searchBar ..
我相对较新的iOS(100小时左右),我正在尝试实现一个没有故事板的UISearchController.是否可以通过编程方式执行此操作?
只是想知道用于Raywenderlich教程的代码如何添加UISearchController和如何使用它UITableViewController我似乎无法让它工作,有人告诉我它可能已经在iOS 8.0中被弃用,有没有人知道关于如何仍然这样做?
该UISearchController始建于UIViewControllerNOT脚本!
我通过单击按钮创建一个表格视图和一个搜索栏.但我需要搜索栏显示在Auto Focus(用户立即输入文本而不需要在搜索栏内单击).我怎样才能做到这一点 ?
我正在努力将搜索栏添加到现有应用中。
我有一个表格,其中填充了从服务器下载的数据,并且正在使用新的UISearchController。
我现在使搜索栏全部正常工作,并且随着用户在搜索栏中键入内容,将显示一个经过过滤的新结果表。
我的问题是如何处理用户从这个新的过滤后的搜索结果表中选择一个项目?
我从过滤后的表中添加了一个新的序列,并添加了didSelectRowAtIndexPath,它的工作原理很好-但是当用户从过滤后的表中选择一个项目时,搜索栏仍然存在,然后单击“取消”会使该应用程序崩溃。
因此,我不确定应该怎么做以及如何处理用户从过滤表中选择项目的问题?
我会保持事物的样子,但添加一些代码以在用户选择项目时取消搜索栏吗?
还是我做错了,有没有办法在用户选择过滤项时将选择从过滤表移回主ViewController表?
一如既往地非常感谢您的协助!
我修改AAPLSearchBarEmbeddedInNavigationBarViewController了Apple的UICatalog示例代码,以便AAPLSearchBarEmbeddedInNavigationBarViewController在选择单元格时将其他实例推送到导航堆栈.在第二个视图控制器中,UISearchBar设置为UINavigationBar的标题视图(就像第一个一样)是不可点击的(与第一个不同).这似乎是一个错误.我如何解决它?这是我修改的UICatalog代码:https:
//github.com/stevemoser/UICatalog
我也用Xcode 6和7进行了测试.两者都打破了.
自动呈现UISearchController和自己呈现搜索控制器之间的行为有所不同。
@implementation MyViewComtroller
// click search barbutton on right of navigationBar
- (void)searchAction:(id)sender {
ArticleSearchViewController *searchResultsController = [[ArticleSearchViewController alloc] init];
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
searchController.searchResultsUpdater = searchResultsController;
searchController.searchBar.delegate = searchResultsController;
searchController.delegate = searchResultsController;
searchController.hidesNavigationBarDuringPresentation = NO;
[self presentViewController:searchController animated:YES completion:nil];
}
@end
@implementation ArticleSearchViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ArticleDetailController * articleDetailController = [ArticleDetailController new];
[(UINavigationController *)self.presentingViewController pushViewController:articleDetailController animated:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
推送操作发生在UISearchController下面。
uinavigationbar uinavigationcontroller uisearchbar ios uisearchcontroller
搜索控制器的系统行为:
在我的应用程序中,点击任何文本后,tableView仍然是灰色的.我无法点击任何搜索过的单元格.不同之处在于,当我搜索时,我使用updateSearchResultsForSearchController和reloadData 更新旧的tableView(搜索后我没有不同的tableView).
问题是如何在searchcontroller中输入任何文本后隐藏这个灰色视图并有机会点击单元格?
我创建搜索控制器的方式:
UISearchController * search = [[UISearchController alloc] initWithSearchResultsController:nil];
search.searchResultsUpdater = self;
self.navigationItem.searchController = search;
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.searchController.searchBar.barTintColor = [UIColor blueColor];
self.navigationItem.searchController.searchBar.delegate = self;
Run Code Online (Sandbox Code Playgroud)
以及我如何更新tableView单元格:
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
self.actualSearchController = searchController;
self.filteredData = [self filterContentForSearchText:searchController.searchBar.text];
[self.tableView reloadData];
}
- (NSMutableArray<MySectionContainter *> *)filterContentForSearchText:(NSString *)text {
NSMutableArray<MySectionContainter *> *sections = [NSMutableArray array];
for (MySectionContainter *section in self.tableData) {
NSArray *objects = [sectionInfo.rowObjects filteredArrayUsingPredicate:[self.filterSource predicateForSearching:text]];
if ([objects count] > 0) { …Run Code Online (Sandbox Code Playgroud) 我在导航项目上使用UISearchController(导航栏已设置为使用barTintColor和tintColor)。关闭搜索控制器后(点击搜索栏的“取消”按钮),后退按钮的tintColor将恢复为默认值(蓝色)。
屏幕截图2:当UISearchController处于活动状态时:

屏幕快照3:关闭UISearchController时(通过点击“取消”),您会看到“后退”按钮的tintColor恢复为默认值(蓝色),而不是白色:

屏幕截图上的代码是:
/// View controller is embedded in a UINavigationController, the root view controller of the startup storyboard.
class ViewController: UIViewController {
lazy var searchController: UISearchController = {
let controller = UISearchController(searchResultsController: nil)
controller.searchBar.tintColor = .white
return controller
}()
override func viewDidLoad() {
super.viewDidLoad()
if let navigationBar = navigationController?.navigationBar {
setupNavigationBar(navigationBar)
}
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
navigationItem.titleView = searchController.searchBar
}
}
func setupNavigationBar(
_ navigationBar: UINavigationBar,
barTintColor: UIColor = …Run Code Online (Sandbox Code Playgroud) ios ×7
swift ×4
uitableview ×3
search ×2
uisearchbar ×2
autofocus ×1
ios13 ×1
iphone ×1
objective-c ×1
tintcolor ×1
xcode ×1