1

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;
4

1 回答 1

1

请注意,我在这里也回答了这个问题:如何让 NSTextFinder 出现

问题是 findBarVisible 仅通过它的容器设置栏的可见性,它实际上并没有告诉 NSTextFinder 本身它需要显示(至少,这是我对它的理解)。

假设您的 textFinder 客户端设置正确,并且您的滚动视图类别设置正确,您仍然需要执行一个操作以使其显示。然后你应该可以让它随意出现和消失。

替换[self.webView scrollView].findBarVisible = YES;

[self.textFinder performAction:NSTextFinderActionShowFindInterface];

另外,请注意,我将 NSTextFinder 作为在 XIB 文件中创建的 IBAction。我不确定这是否会阻止它出现。

于 2013-08-27T02:16:03.370 回答