2017-02-19 78 views
0

我使用NSTokenField,但它指定的延遲NSTokenField不顯示建議彈出

我試過這樣後不顯示與建議的小狗:

class ViewController: NSViewController 
{ @IBOutlet weak var tokenFiled: NSTokenField! 

    override func viewDidLoad() 
    { super.viewDidLoad() 

    tokenFiled.delegate = self 
    tokenFiled.tokenStyle = .default 
    tokenFiled.completionDelay = 0.25 
    } 

    override var representedObject: Any? 
    { didSet { } } 
} 

extension ViewController: NSTokenFieldDelegate, NSTokenFieldCellDelegate 
{ 
    func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>) -> [Any] 
    { 
    let names = ["Name1", "Name 2", "Name3"] 
    return names 
    } 
} 

任何想法,什麼I'米做錯了嗎?

回答

0

明白了,

我使用了錯誤的委託方法。而不是

func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>) -> [Any] 

func tokenField(_ tokenField: NSTokenField, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>?) -> [Any]? 

其現在的工作罰款