【发布时间】:2013-01-30 09:54:50
【问题描述】:
我在应用程序窗口中有一个 NSTextView,它显示了串行端口的传入数据日志。当它到达应用程序时,我将文本附加到日志中:
NSAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: text];
NSTextStorage *textStorage = [SerialOutput textStorage];
[textStorage beginEditing];
[textStorage appendAttributedString:attrString];
[textStorage endEditing];
我想将文本限制为 1000 行,以免应用程序因无限期运行而崩溃。
现在我有一个临时解决方案,基于每周清除日志的 NSTimer,它可以工作,但我更喜欢实施一个聪明的方法,只是限制文本大小并创建循环日志。
有什么想法吗?也许使用方法 insertAttributedString ?
问候, 琼
【问题讨论】:
标签: logging size fixed nstextview nstextstorage