Getting autocomplete to work in swift

前端 未结 12 541
清酒与你
清酒与你 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:48

    Replace your searchAutocompleteEntriesWithSubstring function content with the one below. I hope it would help you.

    func searchAutocompleteEntriesWithSubstring(substring: String)
    {
        autocompleteUrls.removeAll(keepCapacity: false)
    
        for curString in pastUrls
        {
            var myString:NSString! = curString as NSString
    
            var substringRange :NSRange! = myString.rangeOfString(substring)
    
            if (substringRange.location  == 0)
            {
                autocompleteUrls.append(curString)
            }
        }
    
        autocompleteTableView.reloadData()
    }
    

提交回复
热议问题