gpt4 book ai didi

swift - 观察 NSTextView 中的文本变化

转载 作者:行者123 更新时间:2023-11-28 11:37:56 25 4
gpt4 key购买 nike

我最近开始玩 macOS 开发,在过去的 2 天里,我一直在努力处理 TextView 。

我有 Scrollable TextView,它是 NSScrollView(NSTextView.documentView)。每次用户更改文本时,我都需要执行一些操作。

在 iOS 中,这非常简单。我刚刚设置了 UITextView 的委托(delegate)。但是,我在文档中和此处都找不到与 NSTextView 相关的内容。没有 textDidChange 之类的东西。

谢谢大家,感谢帮助。

最佳答案

只需设置 TextView 的委托(delegate)。委托(delegate)必须符合 NSTextViewDelegateNSTextViewDelegate 继承自 NSTextDelegate(参见关系,NSTextViewNSText 的子类)。 NSTextDelegate 定义方法

optional func textDidChange(_ notification: Notification)

关于swift - 观察 NSTextView 中的文本变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54553301/

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