Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa NSTextView:替换所有选项卡_Cocoa_Nstextview - Fatal编程技术网

Cocoa NSTextView:替换所有选项卡

Cocoa NSTextView:替换所有选项卡,cocoa,nstextview,Cocoa,Nstextview,我有一个NSTextView,我想在这里使用空格而不是制表符。我想我会在textStorageWillProcessEditing:中textview委托的replaceCurrencesofString:with字符串:选项:范围:,但它不起作用(撤消中断) 请问,有人知道如何实现这种功能吗?还有别的方法吗 编辑:这是我在textStorageWillProcessEditing:方法中的内容: ts = [notification object]; [[ts mutableString] r

我有一个
NSTextView
,我想在这里使用空格而不是制表符。我想我会在
textStorageWillProcessEditing:
textview委托的
replaceCurrencesofString:with字符串:选项:范围:
,但它不起作用(撤消中断)

请问,有人知道如何实现这种功能吗?还有别的方法吗

编辑:这是我在
textStorageWillProcessEditing:
方法中的内容:

ts = [notification object];
[[ts mutableString] replaceOccurrencesOfString:@"\t"
                                    withString:@"  "
                                       options:NSLiteralSearch
                                         range:[ts editedRange]];

您可以重写keyUp:方法。 如果event.keyCode==keycodefortabwhichintknow:) 然后可以插入四个空格


如果不是这样,当然只需调用[超级按键:theEvent]

我怀疑你真的很接近这项工作。如果您有文本视图的文本存储句柄,则可以对其执行“
replaceCurrencesofString:
”调用。修改这个问题,以显示你迄今为止所做的工作的代码,如果它仍然不起作用,我将尝试为你回答它(如果其他人没有先来回答)。@MichaelDautermann:完成,谢谢!这个中断究竟是如何撤销的?你的代码对我来说似乎很好。当我点击“a”,“tab”,“undo”,redo,然后是“a”,而不是“a”。更准确地说,空格在那里,但光标移动到了错误的位置。另外,当我粘贴较长的文本时,“撤消”只会擦除其中的一部分。与其使用NSTextStorage处理,不如使用NSTextView处理。您可以查看NSTextViewDelegate中的
-textView:shouldChangeTextInRange:replacementString:
-textDidChange:
,或
-textView:didCheckTextInRange:类型:选项:结果:正交法:字数: