Ios UIViewController中带有UITableView的搜索栏

Ios UIViewController中带有UITableView的搜索栏,ios,uitableview,uiviewcontroller,swift2,uisearchbar,Ios,Uitableview,Uiviewcontroller,Swift2,Uisearchbar,我试图在json文件的结果中创建一个搜索过滤器 所以我有以下代码 import UIKit import Alamofire import SwiftyJSON class checkViewController: UIViewController, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate{ @IBOutlet weak var searchBar: UISearchBar! @I

我试图在json文件的结果中创建一个搜索过滤器

所以我有以下代码

import UIKit
import Alamofire
import SwiftyJSON



class checkViewController: UIViewController, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate{



    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var checkTable: UITableView!


     var arrRes = [[String:AnyObject]]()

    var filteredData = [[String:AnyObject]]()


    override func viewDidLoad() {
        super.viewDidLoad()
        checkTable.dataSource = self
        searchBar.delegate = self
        filteredData = arrRes



        Alamofire.request(.GET, "https://example.com/search", parameters: ["q": "", "type": "name"])
            .responseJSON { (responseData) -> Void in
                if((responseData.result.value) != nil) {
                    let swiftyJsonVar = JSON(responseData.result.value!)
                    print(swiftyJsonVar)
                    if let resData = swiftyJsonVar["data"].arrayObject {
                        self.arrRes = resData as! [[String:AnyObject]]
                    }
                    if self.arrRes.count > 0 {
                        self.checkTable.reloadData()
                    }
                }                   
        }    
    }        
     func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }        
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         
            return arrRes.count           
    }       
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("checkInCellView", forIndexPath: indexPath)
        var dict = arrRes[indexPath.row]
        cell.textLabel?.text = dict["name"] as? String
        return cell
    }


}
我试图在我的类中插入
UISearchResultsUpdating
,但我得到一个不是成员的错误。因此,我尝试使用
UISearchBarDelegate
,但在本例中,我只能在[String]数组中找到一种方法,而不能在[[String:AnyObject]]中找到

class ViewController: UIViewController, UITableViewDataSource, UISearchBarDelegate {
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var searchBar: UISearchBar!

    let data = ["New York, NY", "Los Angeles, CA", "Chicago, IL", "Houston, TX",
        "Philadelphia, PA", "Phoenix, AZ", "San Diego, CA", "San Antonio, TX",
        "Dallas, TX", "Detroit, MI", "San Jose, CA", "Indianapolis, IN",
        "Jacksonville, FL", "San Francisco, CA", "Columbus, OH", "Austin, TX",
        "Memphis, TN", "Baltimore, MD", "Charlotte, ND", "Fort Worth, TX"]

    var filteredData: [String]!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        searchBar.delegate = self
        filteredData = data
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("TableCell") as UITableViewCell
        cell.textLabel?.text = filteredData[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return filteredData.count
    }

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
        filteredData = searchText.isEmpty ? data : data.filter({(dataString: String) -> Bool in
            return dataString.rangeOfString(searchText, options: .CaseInsensitiveSearch) != nil
        })

    }

    // This method updates filteredData based on the text in the Search Box
    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
        // When there is no text, filteredData is the same as the original data
        if searchText.isEmpty {
            filteredData = data
        } else {
            // The user has entered text into the search box
            // Use the filter method to iterate over all items in the data array
            // For each item, return true if the item should be included and false if the
            // item should NOT be included
            filteredData = data.filter({(dataItem: String) -> Bool in
                // If dataItem matches the searchText, return true to include it
                if dataItem.rangeOfString(searchText, options: .CaseInsensitiveSearch) != nil {
                    return true
                } else {
                    return false
                }
            })
        }
        tableView.reloadData()
    }
}
有没有办法让[[String:AnyObject]]也能使用它

因为如果我尝试这样做,我会出错

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
    filteredData = searchText.isEmpty ? arrRes : arrRes.filter({(dataString: [String:AnyObject]) -> Bool in
        return dataString.rangeOfString(searchText, options: .CaseInsensitiveSearch) != nil
    })

}
类型“[String:AnyObject]”的值没有成员“rangeOfString”


你知道如何处理这个问题吗?

希望你能从下面的代码中得到答案

override func viewDidLoad() 
{
    super.viewDidLoad()

    var MyStringArray: [String] = ["ABC","XYZ","SomeData"]

    let strDemo : String = "SomeData"

    for indexNo in 0..<MyStringArray.count 
    {

        if MyStringArray[indexNo].rangeOfString(strDemo) != nil
        {
            print("found")
        }
        else
        {
            print("Not found")
        }
    }

}
override func viewDidLoad()
{
super.viewDidLoad()
var MyStringArray:[字符串]=[“ABC”、“XYZ”、“SomeData”]
让strDemo:String=“SomeData”
对于0中的indexNo。。