【问题标题】:Matching title with the Image name in UISearchController Swift将标题与 UISearchController Swift 中的图像名称匹配
【发布时间】:2016-03-21 00:02:05
【问题描述】:

我有一个 tableviewController,我有一个 SearchBar。当我在搜索框中输入自助餐厅名称时,找到的名称会显示错误的图像。

这是我的变量:我应该用另一种语法格式声明带有标题和图像的字典数组吗?

@IBOutlet weak var RetailTableView: UITableView!  //our TableView
        var resultSearch = UISearchController() //our UISearchbar

        var menuItems = [["20/20 Cafe" : "20_20Cafe.jpg"],
                        ["Au Bon Pain": "AuBonPain.jpg"]]

        var menuItemsFiltered = [(String)]()

这是我的 TableViewFunc:

internal func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {  
        let cell = tableView.dequeueReusableCellWithIdentifier("RetailCell", forIndexPath: indexPath) as! ResidentialTableViewCell

        let entry = menuItems[indexPath.row]
        let image = UIImage(named: RetailImagesArray[indexPath.row])

                if self.resultSearch.active
                {
                    cell.RetailLabel.text = menuItemsFiltered[indexPath.row]
                }
                else
                {
                    cell.RetailImage.image = image
                    cell.RetailLabel.text = entry.keys //Not Working
                }

我的搜索功能也不起作用

 func updateSearchResultsForSearchController(searchController: UISearchController) {

        self.FilteredArray.removeAll(keepCapacity: false)
        let searchText = searchController.searchBar.text!.lowercaseString
        FilteredArray = RetailPlacesArray.filter({$0.lowercaseString.rangeOfString(searchText) != nil})

        RetailTableView.reloadData()
    }

请帮忙,我做错了什么?

【问题讨论】:

    标签: ios swift uitableview dictionary uisearchbar


    【解决方案1】:

    如果找不到字符串,rangeOfString 不会返回 nil,而是返回位置为 NSNotFoundNSRange

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多