Getting autocomplete to work in swift

前端 未结 12 530
清酒与你
清酒与你 2020-12-04 15:55

I am trying to implement autocompletion, but can\'t find an example that works in Swift. Below, I\'m tring to convert Ray Wenderlich\'s autocompletion tutorial and example c

12条回答
  •  离开以前
    2020-12-04 16:33

    For future guys, that might get to work on autocomplete texfield with Swift 2, the code provided by @dane works well. but you have to change this line:

    let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier(autoCompleteRowIdentifier, forIndexPath: indexPath) as UITableViewCell
    

    by

    let cell = UITableViewCell(style: UITableViewCellStyle.Default , reuseIdentifier: cellIdentifier)
    

    Also, you might notice that the it is case sensitive, and doesn't work if you enter lowercase string (e.g cats) by default. So to solve this issue you can replace add the option "CaseSensitiveSearch" to the substringRange declaration (in the func searchAutocompleteEntriesWithSubstring). it should look like:

    let substringRange :NSRange! = myString.rangeOfString(substring,options [.CaseInsensitiveSearch])
    

    Hope it will help you save one day!!!

提交回复
热议问题