简体   繁体   English

类型“ ViewController”不符合协议“ UISearchResultsUpdating”

[英]Type 'ViewController' does not conform to protocol 'UISearchResultsUpdating'

I want to set up a tableView to search the cell I needed,but there have a problem. 我想设置一个tableView来搜索所需的单元格,但是有一个问题。 First I use the protocol named UISearchDisplayController but the Xcode warning is not good in IOS 8.0,so I read the protocol UISearchResultUpdating . 首先,我使用名为UISearchDisplayController的协议,但是Xcode警告在IOS 8.0中并不理想,因此我阅读了协议UISearchResultUpdating But when I add the UISearchResultUpdating in my Viewcontroller,there have a mistake in UISearchResultUpdating ! 但是,当我加入UISearchResultUpdating在我的viewController,也出现在了一个错误UISearchResultUpdating

Type 'ViewController' does not conform to protocol 'UISearchResultsUpdating' 类型“ ViewController”不符合协议“ UISearchResultsUpdating”

What should I do to solve? 我该怎么办?

class ViewController:UIViewController,UITableViewDataSource,UITableViewDelegate,UISearchResultsUpdating {

    @IBOutlet weak var tableview: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.
        tools = [TodoModel(id: "1", image: "QQ", title: "聊天", date: DateFromString("2013-12-13")!),
        TodoModel(id: "2", image: "unbrella", title: "下雨", date: DateFromString("2013-12-13")!),
        TodoModel(id: "3", image: "plane", title: "飞行", date: DateFromString("2013-12-13")!)]
        navigationItem.leftBarButtonItem = editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        if tableview == searchDisplayController?.searchResultsTableView{
            return filtertool.count
        }
        else {
            return tools.count

        }
    }

    // Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
    // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        let cell = self.tableview.dequeueReusableCellWithIdentifier("cellinit") as! UITableViewCell
        var tool : TodoModel
        if tableview == searchDisplayController?.searchResultsTableView{
            tool = filtertool[indexPath.row] as TodoModel
        }
        else { tool = tools[indexPath.row] }
        var image = cell.viewWithTag(1) as! UIImageView
        var title: UILabel = cell.viewWithTag(2) as! UILabel
        var date: UILabel = cell.viewWithTag(3) as! UILabel
        image.image = UIImage(named: tool.image)
        title.text = tool.title
        let local = NSLocale.currentLocale()
        let dateformat = NSDateFormatter.dateFormatFromTemplate("yyyy-MM-dd", options: 0, locale: local)
        let datematter = NSDateFormatter()
        datematter.dateFormat = dateformat
        date.text = datematter.stringFromDate(tool.date)
        return cell

    }
        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 65
    }
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
        if editingStyle == UITableViewCellEditingStyle.Delete {
            tools.removeAtIndex(indexPath.row)
            self.tableview.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
        }
    }

    override func setEditing(editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        self.tableview.setEditing(editing, animated: animated)
    }
    @IBAction func close(segue: UIStoryboardSegue){
        tableview.reloadData()
    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "EditingSegue"{
        var vc = segue.destinationViewController as!
        EditingView
        var indexpath = tableview.indexPathForSelectedRow()
            if let index = indexpath {
                vc.tool = tools[index.row]
            }
    }
        }
    func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath){
        let tool = tools.removeAtIndex(sourceIndexPath.row)
        tools.insert(tool, atIndex: destinationIndexPath.row)
    }

    func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return editing
    }
    func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -> Bool{
        filtertool = tools.filter(){$0.title.rangeOfString(searchString) != nil }
        return true
    }
}

It seems like you have not implemented the delegate methods of UISearchResultsUpdating 似乎您尚未实现UISearchResultsUpdating的委托方法

You need to include the following method in your code : 您需要在代码中包含以下方法:

func updateSearchResultsForSearchController(searchController: UISearchController){
  //your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ViewController不符合协议“ UISearchResultsUpdating” - ViewController does not conform to protocol 'UISearchResultsUpdating' 类型“ ViewController”不符合协议 - Type 'ViewController' does not conform to protocol 类型'ViewController'不符合协议'UICollectionViewDataSource' - Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource' 类型“ ViewController”不符合协议“ MCSessionDelegate” - Type 'ViewController' does not conform to protocol 'MCSessionDelegate' 类型“ ViewController”不符合协议“ FBSDKLoginButtonDelegate” - The type 'ViewController' does not conform to protocol 'FBSDKLoginButtonDelegate' ViewController类型不符合协议SKPaymentTransactiionObserver - type ViewController does not conform to protocol SKPaymentTransactiionObserver 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type “ViewController” does not conform to protocol 'UITableViewDataSource" 类型“ViewController”不符合协议“UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM