Ray King
Ray King

Reputation: 11

Matching title with the Image name in UISearchController Swift

I have a tableviewController where I have a SearchBar. When I type in search box a cafeteria name then wrong image displays with the found name.

Here is my variables: Should I declare my dictionary array with title and image in another syntax format?

@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)]()

Here is my 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
                }

My search function is not working either

 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()
    }

Please help, What I am doing wrong?

Upvotes: 1

Views: 139

Answers (1)

TheEye
TheEye

Reputation: 9346

rangeOfString does not return nil if the string is not found, but an NSRange with the location NSNotFound.

Upvotes: 1

Related Questions