标签: uisearchcontroller

UISearchController不会移动我的UITableView

正如你所看到的,我UITableView的卷轴是最大的,但我的桌子不完全可见.为什么?我用UITableViewController

在此输入图像描述

cocoa-touch uitableview ios swift uisearchcontroller

2
推荐指数
1
解决办法
1172
查看次数

UISearchController - 键盘未显示

我正在使用 UISearchController 并且搜索功能除了两件事外都有效。也许它们是相关的: a) 键盘不显示。所以我不能按“搜索”按钮 b) 在我的主 TableView 中,我访问了样式为“副标题”的原型单元格。搜索进行时,显示的单元格为“基本”样式。在这两种情况下(TableViewController 和 SearchViewController),我使用相同的单元格标识符。

有任何想法吗?这里的一些代码:

class OverviewTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let resultsController = SearchResultsController()
        resultsController.birds = birds
        searchController = UISearchController(searchResultsController: resultsController)
        //searchController.dimsBackgroundDuringPresentation = true

        let searchBar = searchController.searchBar
        searchBar.scopeButtonTitles = ["One", "Two"]
        searchBar.placeholder = "Search"
        searchBar.sizeToFit()
        tableView.tableHeaderView = searchBar
        searchController.searchResultsUpdater = resultsController
Run Code Online (Sandbox Code Playgroud)

第二类:

class SearchResultsController: UITableViewController, UISearchResultsUpdating {

    var items: [Item] = []
    var filtered: [Item] = []

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}

// MARK: …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uisearchcontroller

2
推荐指数
1
解决办法
1475
查看次数

如何让UISearchController等待点击搜索

我正在尝试在我的SWIFT代码中实现搜索。我希望它等到单击搜索按钮后再执行任何操作。到目前为止我所拥有的。

func updateSearchResultsForSearchController(searchController: UISearchController)
{
    self.filteredCats.removeAll(keepCapacity: false)
    filteredCats = art.filter{
        $0.sarticleTitle.lowercaseString.rangeOfString(searchController.searchBar.text!.lowercaseString) != nil
    }
        print(searchController.searchBar.text)
        self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

用户输入内容后,它将打印出所有信息。我希望它一直等到单击搜索按钮或用户完成所有输入为止。

ios swift uisearchcontroller

2
推荐指数
1
解决办法
1807
查看次数

UITableViewController 中带有 UISearchController 的自定义单元格(结果控制器)

我正在尝试实现一个 UISearchController(而不是已弃用的 UISearchDisplayController)

我面临着一个可笑的时间进食问题。

当我尝试时,dequeueResusableCellWithIdentifier它不适用于我的CellAutocompletion(UITableViewCell 子类化)

像这样 :

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let item = filteredProducts[indexPath.row]

    let cell:CellAutocompletion = self.tableView.dequeueReusableCellWithIdentifier("suggestionCell") as! CellAutocompletion

    cell.itemLabel?.text = item.item_name;

    return cell
}
Run Code Online (Sandbox Code Playgroud)

这个扔我 fatal error: unexpectedly found nil while unwrapping an Optional value

但是当我这样做时:

    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "suggestionCell");
Run Code Online (Sandbox Code Playgroud)

有用。因此,对于默认的 iOS 单元,它可以工作,而我的自定义单元则不能。任何的想法?

我想我问了错误的tableview,但考虑到我在另一个VC使用的UISearchController中包含的TableviewController中,我迷路了。

我的主要 VC实例化了我的 searchController 和出现问题的 TableViewController。

    //ViewDidLoad
    resultsTableController = ProductResultTabController();
    resultsTableController.tableView.delegate = self;

    self.searchController = UISearchController(searchResultsController: resultsTableController);
    searchController.searchResultsUpdater …
Run Code Online (Sandbox Code Playgroud)

uitableview custom-cell ios swift uisearchcontroller

2
推荐指数
1
解决办法
1114
查看次数

SearchBar 和 NavigationBar 之间的空白区域 - Swift

我有一个简单的tableViewController,一个searchBar带范围和一个navigationBar.

当我点击我的searchBar我看到我的范围和所有工作。然后我单击一行并转到我DetailPage的搜索栏并没有隐藏(我不知道为什么)。

所以我点击取消,然后我回到我的tableView. 当我返回到我的 tableView 时,我SearchBar和我的NavigationBar.

空格处

这是我的代码:

      self.resultSearchController = ({
            let controller = UISearchController(searchResultsController: nil)
            controller.searchResultsUpdater = self
            controller.hidesNavigationBarDuringPresentation = true
            controller.dimsBackgroundDuringPresentation = false
            controller.searchBar.sizeToFit()
            controller.searchBar.scopeButtonTitles = ["Title", "Author", "Location", "Price", "User"]
            self.tableView.tableHeaderView = controller.searchBar
            return controller
        })()

 func updateSearchResults(for searchController: UISearchController)
    {
        let scopes = resultSearchController.searchBar.scopeButtonTitles
        let currentScope = scopes![resultSearchController.searchBar.selectedScopeButtonIndex] as String
        filterContentForSearchText(searchText: searchController.searchBar.text!, scope: currentScope)
    }
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar ios swift uisearchcontroller

2
推荐指数
1
解决办法
2409
查看次数

呈现 UISearchController 与状态栏重叠

我有一个UISearchController我编程呈现当用户触摸的按钮。我的问题是搜索栏与状态重叠(见截图)

在此处输入图片说明

我有以下代码用于展示 UISearchController

func presentSearchController() {
    let resultsController = ResultsViewController()

    self.searchController = UISearchController(searchResultsController: resultsController)
    self.searchController.searchBar.searchBarStyle = .prominent

    searchController.hidesNavigationBarDuringPresentation = false
    searchController.searchResultsUpdater = resultsController

    self.definesPresentationContext = true

    self.present(self.searchController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

编辑:我的问题不是UISearchBar 与 iOS 中的状态栏重叠,因为我没有直接使用搜索或其框架

uisearchbar ios swift uisearchcontroller

2
推荐指数
1
解决办法
2439
查看次数

未显示UISearchController

我正在UISearchController按照教程进行学习。但是,UISearchBar未显示。这是我的代码:

let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
    super.viewDidLoad()
    searchController.searchResultsUpdater = self
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Search Candies"
    navigationItem.searchController = searchController
    definesPresentationContext = true
}
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序的样子:

在此处输入图片说明

我怎样才能解决这个问题?

uisearchcontroller swift3

2
推荐指数
1
解决办法
1070
查看次数

使用 UISearchController 的好处?

使用UISearchControllerover 有UISearchBarDelegate什么好处?这种差异对我来说似乎有点微妙。特别是,updateSearchResults似乎与textDidChange. 假设我们不使用新的 VC 来显示搜索结果,我不明白为什么要UISearchControllerUISearchBarDelegate.

uisearchbar ios uisearchcontroller

2
推荐指数
1
解决办法
878
查看次数

调整 UISearchController 的 searchBar 的 insets

我正在尝试一些设计,我希望所有子视图的边距都相等,为 25 像素。UISearchControllersearchBar对两侧一个16px的填充开箱。我是否必须从头开始编写搜索栏文本字段,或者是否有任何方式,未记录的、混合的或其他方式来完成根据我的口味抵消本机栏?

在此处输入图片说明

uikit ios swift uisearchcontroller

2
推荐指数
1
解决办法
1310
查看次数

在没有 UINavigationController 的情况下如何使用 UISearchController?

当视图控制器未嵌入 UINavigationController 中时,我不明白如何使用 UISearchController 。

为了说明我的意思,请尝试下载此代码:https://developer.apple.com/documentation/uikit/view_controllers/displaying_searchable_content_by_using_a_search_controller

然后,删除导航控制器并使表格搜索场景成为初始视图控制器。该表仍然正常工作,但搜索控制器不显示。

有没有办法修改该代码,以便您可以使用 UISearchController 而无需将其嵌入导航控制器中?我在文档中没有看到任何需要 UINavigationController 的内容。所有与此相关的堆栈溢出问题都告诉您单独使用 UISearchBar。我对使用 UISearchController 特别感兴趣。

uikit uinavigationcontroller ios swift uisearchcontroller

2
推荐指数
1
解决办法
1305
查看次数