简体   繁体   中英

Does Not Conform To Protocol Error

I am making a stock application and I have an issue in my main View Controller. The error message is Type "ViewController" does not conform to protocol 'AutocompleteDelegate'. If anyone knows how to solve this it would be much appreciated.

Here is my code.

extension ViewController:AutocompleteDelegate{
func autoCompleteTextField() -> UITextField {
    return self.textInput
}
func autoCompleteThreshold(textField: UITextField) -> Int {
    return 2
}

func autoCompleteHeight() -> CGFloat {
    return CGRectGetHeight(self.view.frame) / 3.0
}


func didSelectItem(item: AutocompletableOption) {
    var outPut=""
    for char in item.text.characters {
        if (char >= "A" && char <= "z"){
            outPut.append(char)
        }
        else{
            break
        }
    }

    self.textInput.text = outPut
}

}

I think you are missing implementation for following method

func autoCompleteItemsForSearchTerm(term: String) -> [AutocompletableOption]

Any conforming type that conforms to AutocompleteDelegate, requires to have following instance methods

func autoCompleteTextField() -> UITextField

func autoCompleteThreshold(textField: UITextField) -> Int

func autoCompleteItemsForSearchTerm(term: String) -> [AutocompletableOption]

func autoCompleteHeight() -> CGFloat

func didSelectItem(item: AutocompletableOption) -> Void

You already implemented the other 4 methods, just need to have autoCompleteItemsForSearchTerm implementation as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM