我正在使用以下代碼取消選擇NSTextView
,建議使用here。不幸的是,一切都沒有發生。我試過我知道的調試它,但一切似乎都正常工作,但它不影響NSTextView
。以編程方式取消選擇NSTextView中的文本?
代碼:
// Sets the scrolling bounds and behavior. This might be useful, but I don't know
[[textView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[textView textContainer] setWidthTracksTextView:FALSE];
// The code for deselecting, beginning by making sure it is actually selected (for testing only, as strange as it is)
[textView setSelectable:TRUE];
[textView setDelegate:self];
[_window makeFirstResponder:textView];
NSText *fieldEditor = [_window fieldEditor:TRUE forObject:textView];
[fieldEditor setSelectedRange:NSMakeRange([[fieldEditor string] length],0)];
[fieldEditor setNeedsDisplay:YES];
爲什麼這不起作用任何想法?我確定我的網點設置正確,因爲我可以操縱其他東西,比如它的字符串值。
可可-dev的(我認爲)線程即將NSText *場*,不NSText *查看*。這兩者非常不同:NSTextField是一種控件,因此依賴於字段編輯器,而NSTextView不是控件,也不使用字段編輯器。 –
我什至沒有注意到。非常感謝。 – Justin