私は自分の答えを見つけたので、他の人のためにここにそれを行う方法があります.
まず、制御できるように NSTextFinder のインスタンスが必要です。それをコードで設定します。
textFinder = [[NSTextFinder alloc] init];
[textFinder setClient:textView];
[textFinder setFindBarContainer:[textView enclosingScrollView]];
[textView setUsesFindBar:YES];
[textView setIncrementalSearchingEnabled:YES];
最初の回答: 視覚的なフィードバックをクリアするには、2 つの方法のいずれかを実行できます。視覚的なフィードバックをキャンセルできます...
[textFinder cancelFindIndicator];
または、textView コンテンツを変更しようとしていることを NSTextFinder に警告できます...
[textFinder noteClientStringWillChange];
2 番目の回答: グローバル NSFindPboard があります。それを使用して検索を設定できます。
// change the NSFindPboard NSPasteboardTypeString
NSPasteboard* pBoard = [NSPasteboard pasteboardWithName:NSFindPboard];
[pBoard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString, NSPasteboardTypeTextFinderOptions, nil] owner:nil];
[pBoard setString:@"new search" forType:NSStringPboardType];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSTextFinderCaseInsensitiveKey, [NSNumber numberWithInteger:NSTextFinderMatchingTypeContains], NSTextFinderMatchingTypeKey, nil];
[pBoard setPropertyList:options forType:NSPasteboardTypeTextFinderOptions];
// put the new search string in the find bar
[textFinder cancelFindIndicator];
[textFinder performAction:NSTextFinderActionSetSearchString];
[textFinder performAction:NSTextFinderActionShowFindInterface]; // make sure the find bar is showing
しかし、問題があります。そのコードの後、検索バーの実際のテキスト フィールドは更新されません。ファーストレスポンダーを切り替えると、更新できることがわかりました...
[myWindow makeFirstResponder:outlineView];
[myWindow makeFirstResponder:textView];