Find Bar does not show up with WebView's Scroll View as the findBarContainer

436 views Asked by At

I have a TextFinderController object that implements the NSTextFinderClient protocol, and a WebView's WebDynamicScrollBarsView (which is an NSScrollView) set as the NSTextFinder's findBarContainer. When I try to make the findBar visible in the ScrollView by setting findBarVisible to YES I am not observing a result. I have noticed that the ScrollView's findBarView is null even after setting the findBarContainer. I am using this code to get the ScrollView from the WebView. This is a Mac application and not an iOS application. How do I get the findBar to show up in the WebView?

self.textFinder = [[NSTextFinder alloc] init];
self.textFinder.client = self.textFinderController;
self.textFinder.findBarContainer = [self.webView scrollView];
[self.webView scrollView].findBarPosition = NSScrollViewFindBarPositionAboveContent;
[self.webView scrollView].findBarVisible = YES;
1

There are 1 answers

0
Joel Fischer On BEST ANSWER

Note that I have also answered this question here: How do I get NSTextFinder to show up

The problem is that findBarVisible only sets the visibility of the bar through it's container, it does not actually tell the NSTextFinder itself that it needs to show up (at least, that is my understanding of it).

Assuming that you have your textFinder client set up properly, and your scrollview category set up properly, you still need to implement an action to make it appear. Then you should be able to make it appear and disappear at will.

Replace [self.webView scrollView].findBarVisible = YES; with

[self.textFinder performAction:NSTextFinderActionShowFindInterface];

Also, note that I have the NSTextFinder as an IBAction created in the XIB file. I'm not sure if that prevents it from appearing or not.