Tag: uisearchbar

Swift – 自定义SearchController和SearchBar

我试图重新创build在雅虎财经应用程序中看到的search字段。 我跟着一个在线教程来定制UISearchBar和UISearchController,但是我仍然有一些问题。 如果你们中的任何一个人能够打开我的项目,看看哪里出了问题,哪里需要添加这些线路,哪怕这些线路真的很棒。 我的尝试解决scheme项目可以在这里find: https : //github.com/jordanw421/yahoofinance 1)如何让查询出现的时候,search栏处于激活状态(文本向左​​,input指示灯闪烁)? 在下面的链接中,您可以看到我在说什么,当button被按下时,search视图被加载,search栏立即被激活。 我试过使用: customSearchController.definesPresentationContext = true customSearchController.isActive = true customSearchController.searchBar.becomeFirstResponder() 但是这并没有奏效。 我应该在prepareForSegue的初始视图控制器中设置这些吗? 2)如何设置键盘外观(黑暗),并添加一个button的键盘工具栏? 我能够得到这个工作非自定义search栏,但出于某种原因,这些现在不工作: customSearchController.searchBar.keyboardAppearance = .dark 和 func addKeyboardButton() { let keyboardToolbar = UIToolbar() keyboardToolbar.sizeToFit() keyboardToolbar.isTranslucent = false keyboardToolbar.barTintColor = UIColor.blue let addButton = UIButton(type: .custom) addButton.frame = CGRect(x: keyboardToolbar.frame.size.width / 2, y: keyboardToolbar.frame.size.height / 2, width: […]

Swift:使用SearchBarsearch这两个部分,而不是合并它们

使用Swift 3,该应用程序是使用PHP和JSON从MYSQL数据库读取的博客阅读器。 目前我的SearchBar没有做我想做的事情,我在mainArray(第一部分)中search'All'范围。 当它被过滤时,被过滤的对象被移动到filteredArray。 我同时做了这个,因为我无法弄清楚如何让它做我想做的事情。 它应该做的是这样的,当用户search一个对象时,我希望对象显示在mainArray或者followedArray中,而不是将它移动到不同的数组,所以它不会合并。 基本上过滤tableview,而不是删除任何部分或组合任何对象,因为它会混淆用户通过不知道该对象在哪个部分,当然,确保范围栏正常工作。 学习如何实施一个search栏,以便当我尝试进一步提高水平时,可以看到我的麻烦。 谢谢! SearchBar和范围代码 let searchController = UISearchController(searchResultsController: nil) override func viewDidLoad() { // Search Bar searchController.searchResultsUpdater = self searchController.dimsBackgroundDuringPresentation = false definesPresentationContext = true myTableView.tableHeaderView = searchController.searchBar searchController.searchBar.backgroundColor = UIColor.white searchController.searchBar.barTintColor = UIColor.white // Scope Bar searchController.searchBar.scopeButtonTitles = ["All", "Released", "Unreleased", "Free"] searchController.searchBar.delegate = self } // Title […]

closuresUISearchBar

我有在searchBarCancelButtonClicked:中运行的代码searchBarCancelButtonClicked:我想运行相同的代码时,用户点击离开searchsearchBarCancelButtonClicked: ,即使取消不一定是点击。 我目前的代码是在下面,但有一个问题,我不明白。 我已经在search栏下面放置了一个UIView,当点击运行一个方法,做我想要的。 问题是,当search栏处于活动状态时,与uisearchbar关联的半透明视图出现在我的视图之上,单击该视图仍然会closuressearch栏,但不运行我的方法。 search栏解散后,单击视图确实运行我的方法,所以我知道这是好的。 基本上我需要能够使视图手势激活而search栏是第一响应者。 – (BOOL)searchBarShouldBeginEditing:(UISearchBar*)searchBar { UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSearch:)]; UIView *transparentView = [[UIView alloc]initWithFrame:transparentViewRect]; [transparentView setBackgroundColor:[UIColor blackColor]]; [transparentView addGestureRecognizer:singleTap]; [self.view addSubview:transparentView]; [self.view bringSubviewToFront:transparentView]; return YES; } – (void) dismissSearch:(UITapGestureRecognizer *)tapGesture { //Run my code }

search栏在input时从视图中消失

我在ViewDidLoad()添加了SearchBar到我的TableView中: self.searchBar = UISearchController(searchResultsController: nil) self.searchBar.searchResultsUpdater = self self.searchBar.dimsBackgroundDuringPresentation = false self.searchBar.searchBar.sizeToFit() self.tableView.tableHeaderView = self.searchBar.searchBar self.tableView.reloadData() 一切工作正常,但是当我点击这个SearchBar它消失。 这意味着,我仍然可以打字,我可以看到结果,但是,没有看到SearchBar 。 我实现了UISearchBarDelegate ,我一直在试图添加 func searchBarTextDidBeginEditing(searchBar: UISearchBar) { self.navigationController?.navigationBarHidden = false } func searchBarTextDidEndEditing(searchBar: UISearchBar) { self.navigationController?.navigationBarHidden = true } 但它仍然不起作用。 你有什么想法,为什么这个Search Bar消失? 这个问题的解决方法是(像@sandy悲伤)在viewDidLoad()写这行代码 self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true 但现在我有一个新的问题,这是什么意思当我在TableViewselect行并显示新的VievController , SearchBar不会消失,我在新的视图中看到它。 为什么?

NavigationBar IOS中的SearchBar

我尝试使用导航栏大标题,并添加search栏导航控制器。 search栏显示在导航标题下。 它应该隐藏,直到我刷下来。 我明白,默认行为是隐藏的,除非我设置“navigationItem.hidesSearchBarWhenScrolling = false”。 即使我添加“navigationItem.hidesSearchBarWhenScrolling = true”,它不起作用。 我创build了一个新的应用程序来testing这个function。 它embedded了ViewController和Navigation Controller。 以下是我的代码: class ViewController: UIViewController { let searchController = UISearchController(searchResultsController: nil) override func viewDidLoad() { super.viewDidLoad() navigationController?.navigationBar.prefersLargeTitles = true navigationItem.searchController = searchController // navigationItem.hidesSearchBarWhenScrolling = true } }

删除UISearchBar中的清除button

我想从UISearchBar中删除清除button(灰色x)。 我试图像这个答案中所描述的那样做 ,但它不起作用。 我将答案和下面的注释中的Objective-C代码翻译成以下Swift代码: for subview in searchBar.subviews { configureSearchBarView(subview as UIView) } func configureSearchBarView(view: UIView) { for subview in view.subviews { self.configureSearchBarView(subview as UIView) } if subview.conformsToProtocol(UITextInputTraits) { var clearView = view as UITextField clearView.clearButtonMode = UITextFieldViewMode.Never } } 不幸的是,这并没有删除清除button。 另外一个答案build议与appearanceWhenContainedIn一起工作,但是这个方法似乎并没有在Swift中实现。 有任何想法吗?

如何在iOS7中更改UISearchBar的inputView?

在iOS6中,我使用下面的代码来更改UISearchbar的inputView for (UIView *view in _searchBar.subviews) { if ([view isKindOfClass: [UITextField class]]) { UITextField* textField = (UITextField*)view; [textField setInputView:_myKeyboard]; break; } } iOS7中的UISearchbar已经改变,我不知道如何findtextField来改变inputView。 请帮忙! 谢谢!

UISearchController错位UISearchBar

我在模态页上使用UISearchController来允许用户search一些数据。 该页面使用表格视图控制器devise,并且searchBar位于tableViewCell中。 当用户点击searchBar时,UISearchControlleranimation布局将表格标题滑动到页面顶部并移动search栏。 然而,它并没有在正确的地方结束。 它没有足够的移动。 任何人有关于如何帮助UISearchController正确定位searchBar的build议? 在点击search栏之前(看起来确定) 点击search栏(search栏位置不正确)

加载了笔尖,但没有得到一个UITableView

我一直在YouTube上关注本教程( 第1 部分和第2部分 )。 我已经完成了两个video,并使用以下代码将视图控制器与父视图控制器连接起来: – (IBAction)searchButtonClicked:(id)sender { NSLog(@"It works."); SearchViewController *searchViewControl = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchControllerNav"]; [self presentViewController:searchViewControl animated:YES completion:nil]; } 这个代码确实有效,因为这是我用于其他模式视图控制器的相同格式,所以我知道这不是问题。 无论如何,当我点击视图控制器中的searchbutton,它应该popupSearchViewController 。 然而,该应用程序崩溃,而是给了我这个错误消息: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "jp7-vt-IdA-view-Jer-xW-qlD" nib but didn't get a UITableView.' 我正在使用这个应用程序的故事板。 有什么我失踪? 先谢谢你。 一个侧面的问题:我也得到一个警告,说只要显示isFiltered == YES Comparison between pointer and integer ('BOOL […]

UISearchController searchBar在第一次点击时消失

我已经在TableView中实现了一个UISearchController,由导航控制器推送。 首先我的问题是,每当我点击SearchBar时,它就会消失。 当我input一些文字时,它会起作用,但它保持完全空白。 然后我设法使用这个代码半解决问题: – (void)searchForText:(NSString*)searchText { [self.view addSubview:villeSearchController.searchBar]; } 因为现在是半工作的,当我点击search栏时,它会空白,但是如果我input一个字符,就会再次出现,然后它就停留在那里,不pipe怎样。 直到我取消search,然后再次点击它,在这种情况下,它空白。 我做了一些testing,并且这个方法(searchForText)在第一次点击时被调用,所以这不是原因。 有谁知道我可以如何解决这个问题,并使第一次点击search栏出现? 编辑: 这是我如何初始化SearchController: villeSearchController = [[UISearchController alloc] initWithSearchResultsController:nil]; villeSearchController.searchResultsUpdater = self; villeSearchController.dimsBackgroundDuringPresentation = NO; villeSearchController.searchBar.delegate = self; villeTableView.tableHeaderView = villeSearchController.searchBar; villeSearchController.searchBar.scopeButtonTitles = @[]; self.definesPresentationContext = YES; [villeSearchController.searchBar sizeToFit];