Tag: uisearchcontroller

UITableViewHeader的UISearchBar子视图?

我想添加一个UISearchBar到已经有一个标题视图的UITableView。 当我尝试将search栏添加到现有的页眉视图,直到我点击它,在这一点上,我得到The view hierarchy is not prepared for the constraint ,这似乎是因为search栏不是一个直接的子视图tableview所以当UISearchController试图更新它不能的约束时。 解决这个问题的唯一方法就是将表格视图标题放在search栏中,然后一切正常,但是当然我会丢失已经在标题视图中的其他视图。

快速search数组中的对象

我试图使用UISearchController创build一个searchfunction。 但是,我似乎不能使它与我的团队对象工作。 我已经开始创build一个包含一个ID,名称和短名称的团队对象。 然后,我从URL中检索teamData,并将Team Objects添加到填充到tableView中的数组中。 这个tableView包含一个searchController,它可以过滤数据,但没有任何反应。 arrays var teamArray = Array<Team>() var filteredTableData = [String]() GetTeams函数 func getTeams(url: String) { isApiCalling = true request(.GET, url, parameters: nil) .response { (request, response, data, error) in if error == nil { let data: AnyObject = data! let jsonArray = JSON(data: data as! NSData) for (key: String, subJson: […]

iOS8无法在UISearchController的search栏上隐藏取消button

我的目标是防止取消button出现在UISearchController的search栏中。 我使用UISearchController示例代码从Apple的Table Search开始,并隐藏了取消button,如下面的代码片段所示。 但是,当用户点击文本字段时,取消button仍然出现。 任何帮助? override func viewDidLoad() { super.viewDidLoad() resultsTableController = ResultsTableController() searchController = UISearchController(searchResultsController: resultsTableController) searchController.searchResultsUpdater = self searchController.searchBar.sizeToFit() tableView.tableHeaderView = searchController.searchBar searchController.searchBar.delegate = self //Hide cancel button – added by me searchController.searchBar.showsCancelButton = false …

更改iOS 8中的UISearchBar取消button文本

我想更改从iOS的UISearchBar中取消button的“取消”的“完成”的文本。我正在使用UISearchController。 我已经尝试了iOS 6和iOS 7的不同方法,他们不工作。 有没有人做到这一点?

UISearchController iOS 11自定义

在iOS 11之前,我一直使用下面的代码来自定义UISearchControllersearch栏的外观: var searchController = UISearchController(searchResultsController: nil) searchController.searchBar.setDefaultSearchBar() searchController.searchResultsUpdater = self if #available(iOS 11.0, *) { navigationItem.searchController = searchController } else { tableView.tableHeaderView = searchController.searchBar } extension UISearchBar { func setDefaultSearchBar() { self.tintColor = UIColor.blue self.searchBarStyle = .minimal self.backgroundImage = UIImage(color: UIColor.clear) let searchBarTextField = self.value(forKey: "searchField") as! UITextField searchBarTextField.textColor = UIColor.white searchBarTextField.tintColor = UIColor.blue […]

UISearchController searchBar框架只能在第一次点击时resize

我刚刚在一个普通的UIViewController中实现了一个UISearchController,而且我有一个奇怪的问题。 我有一个UIView完全适应我想我的UISearchBar采取的大小。 在第一次启动的视图,我把我的UISearchBar作为一个子视图添加到这个UIView。 但是当我启动它的时候,UISearchBar并不占用其父UIView的大小 – 它只占用整个屏幕的宽度。 如您所见,它与右侧的button重叠。 但是,一旦我点击search栏并取消它,它调整到我想要的确切大小。 这里可能是什么问题? 我已经尝试将AutoLayout约束从SearchBar添加到其父视图,但它似乎并没有改变任何东西。 不[UIView addSubview:]处理这个?

如何在embedded在UINavigationController中的UISearchController中添加范围button

我有一个应用程序呈现embedded在UINavigationController中的MKMapView。 在UINavigationController我已经把一个UISearchController。 当用户触摸UISearchController时,它显示一个UITableViewController。 它工作正常,而我不在UISearchController中添加范围button。 这里是我启动App时UINavigationController中UISearchController的屏幕截图。 接下来,当我触摸UISearchController时,它将显示UITableViewController和scopebutton。 在这里,我们已经可以看到这个范围button有一个问题,因为它们没有很好地集成在UISearchController中(颜色应该是半透明的) 接下来,当我触摸取消button返回到主视图控制器,UISearchController不恢复其原始样式 它有一个深灰色的边框(可能来自范围button)。 以下是我在主视图控制器中添加UISearchController的方法 func initSearchController() { let mySearchController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SearchControllerId") as! SearchController self.searchController = UISearchController(searchResultsController: mySearchController) mySearchController.theSearchController = self.searchController mySearchController.delegate = self // Configure the UISearchController self.searchController.searchResultsUpdater = self self.searchController.delegate = self self.searchController.searchBar.delegate = self self.searchController.searchBar.placeholder = "data.." self.searchController.hidesNavigationBarDuringPresentation = false self.searchController.dimsBackgroundDuringPresentation = true self.navigationItem.titleView […]

embedded到UISplitViewController中时,iOS11 UISearchBar在UINavigationBar中丢失

奇怪的事情似乎发生在UISplitViewController的详细视图上使用新的iOS 11的navigationItem.searchController方法。 searchBar在第一个演示文稿中部分显示为空白,然后出现在错误的UITableViewController ,但在UITableViewController的一些推送和popup之后自行更正。 我曾经把searchBar放在tableHeaderView ,但是我根据WWDC的build议更改了代码: if (@available(iOS 11.0, *)) { self.navigationItem.searchController = self.searchController; self.navigationItem.hidesSearchBarWhenScrolling = NO; } else { self.tableView.tableHeaderView = self.searchController.searchBar; } 这个例子是使用标准的示例代码( UISplitViewController默认项目和UISearchController的苹果演示为iOS 11更新(使用单个UITableViewController ))。 包含searchController的初始视图如下所示: 然后单击一个UITableView项目产生这样的: 然而,点击一个UITableView项目并返回两次 – 它看起来应该是: 和: 我试图确定为什么UISearchController的苹果示例工作,我的代码没有。 主要区别在于embedded在详细视图中的UISplitViewController中。 这意味着如果在紧凑模式下显示堆栈中有一个额外的UINavigationController 。 我发现如果我的seque避免了多余的UINavigationController – 它工作正常(但打破设备旋转)。 同样改变赛格模式允许它工作。 我注意到这是类似于这个旧的问题: UISplitViewController新的UISearchController问题与UISearchBar 我已经创build了一个演示问题的示例项目( 示例代码:searchControllerDemo ) 我很难理解发生了什么事情。 所以任何帮助将非常感激。

在iOS11的tableHeaderView中使用UISearchController和UISearchBar

有没有人成功保留UISearchBar在UITableView在ios11 tableHeaderView ? iPhone X在横向上通常会出现问题: Applebuild议使用新的searchController属性: if (@available(iOS 11.0, *)) { self.navigationItem.searchController = self.searchController; self.navigationItem.hidesSearchBarWhenScrolling = NO; } else { self.tableView.tableHeaderView = self.searchController.searchBar; } 但是,这并不总是奏效。 这是一个代码示例: embedded到UISplitViewController中时,iOS11 UISearchBar在UINavigationBar中丢失 所以试图在tableHeaderView保留searchBar – 实际的第一步是应用适当的自动布局约束: if (@available(iOS 11.0, *)) { UILayoutGuide *guide = self.tableView.safeAreaLayoutGuide; searchBar.translatesAutoresizingMaskIntoConstraints = NO; [searchBar.leftAnchor constraintEqualToAnchor:guide.leftAnchor].active = YES; [searchBar.rightAnchor constraintEqualToAnchor:guide.rightAnchor].active = YES; } searchBar在显示时大小正确: 但是,当UISearchBar被激活时会出现问题: 这似乎是一个老问题。 […]

按对象searchController的数组进行过滤

我创build了一个searchController,因此我试图根据UISearchController中的文本来过滤内容。 我已经创build了一个自定义对象,如下所示。 我试过使用NSPredicate,但不断得到: cannot convert value of type NSPredicate to expected type @noescape (organization) throws… class Organization: Object { var id: Int = 0 var name: String = "" var shortName: String = "" var image: NSData = NSData() var pinImage: NSData = NSData() let locations = List<Location>() } 然后我在我的ViewController中有一个名为sortedLocations的数组,其中包含一些Organization对象。 我到目前为止所尝试的是: func updateSearchResultsForSearchController(searchController: UISearchController) { […]