我在我的应用程序中集成了自动完成事件。配置textfield
时出现此错误
不能使用索引为“ NSAttributedStringKey”的下标“ [String:AnyObject]”的值
请检查以下代码:
fileprivate func configureTextField(){
print("i am here 4")
autocompleteTextfield.autoCompleteTextColor = UIColor(red: 128.0/255.0, green: 128.0/255.0, blue: 128.0/255.0, alpha: 1.0)
autocompleteTextfield.autoCompleteTextFont = UIFont(name: "HelveticaNeue-Light", size: 12.0)!
autocompleteTextfield.autoCompleteCellHeight = 35.0
autocompleteTextfield.maximumAutoCompleteCount = 20
autocompleteTextfield.hidesWhenSelected = true
autocompleteTextfield.hidesWhenEmpty = true
autocompleteTextfield.enableAttributedText = true
***var attributes = [String:AnyObject]()
attributes[NSForegroundColorAttributeName] = UIColor.black
attributes[NSFontAttributeName] = UIFont(name: "HelveticaNeue-Bold", size: 12.0)
autocompleteTextfield.autoCompleteAttributes = attributes***
}
我在 NSForegroundColorAttributeName,NSFontAttributeName和属性上出错
对于自动完成功能,我导入了自动完成UITextfield
文件。我在以下方法中遇到了以上错误:
> open var autoCompleteAttributes:[String:AnyObject]?
fileprivate func commonInit(){
hidesWhenEmpty = true
autoCompleteAttributes = [NSForegroundColorAttributeName.rawValue:UIColor.black]
autoCompleteAttributes![NSFontAttributeName] = UIFont.boldSystemFont(ofSize: 12)
self.clearButtonMode = .always
self.addTarget(self, action: #selector(AutoCompleteTextField.textFieldDidChange), for: .editingChanged)
self.addTarget(self, action: #selector(AutoCompleteTextField.textFieldDidEndEditing), for: .editingDidEnd)
}
此行出现错误 autoCompleteAttributes![NSFontAttributeName] 。我没有发生任何事情,请检查代码...