gpt4 book ai didi

swift - NSTokenField 不显示建议弹出窗口

转载 作者:行者123 更新时间:2023-11-30 12:40:12 24 4
gpt4 key购买 nike

我使用 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
}
}

有什么想法吗,我做错了什么?

最佳答案

明白了,

我使用了错误的委托(delegate)方法。

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]? 

现在工作正常

关于swift - NSTokenField 不显示建议弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42328116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com