Tengo una aplicación Mac Cocoa con una vista web que contiene algo de texto. Me gustaría buscar a través de ese texto usando la barra de búsqueda predeterminada proporcionada por NSTextFinder. Tan fácil como parece leer a través de la referencia de clase NSTextFinder, no puedo mostrar la barra de búsqueda. ¿Qué me estoy perdiendo?¿Cómo puedo obtener NSTextFinder para mostrar
Como comentario:
- Sí, he intentado establecer findBarContainer a un punto de vista diferente, lo mismo. Me volvió de nuevo a la vista de desplazamiento para eliminar la complejidad en la depuración de
- performTextFinderAction está llamada a realizar la operación de búsqueda
**App Delegate:**
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.textFinderController = [[NSTextFinder alloc] init];
self.webView = [[STEWebView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, 200)];
[[self.window contentView] addSubview:self.webView];
[self.textFinderController setClient:self.webView];
[self.textFinderController setFindBarContainer:self.webView.enclosingScrollView];
[[self.webView mainFrame] loadHTMLString:@"sample string" baseURL:NULL];
}
- (IBAction)performTextFinderAction:(id)sender {
[self.textFinderController performAction:[sender tag]];
}
**STEWebView**
@interface STEWebView : WebView <NSTextFinderClient>
@end
@implementation STEWebView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
}
- (NSUInteger) stringLength {
return [[self stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"] length];
}
- (NSString *)string {
return [self stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];
}
Me encontré con esta pregunta mientras buscaba si webview puede ser paierd con un NSTextFinder. Hasta donde puedo ver, esto resuelve un problema más fácil donde el texto en la vista web es simple. La discusión sobre el problema más general está en http: //www.cocoabuilder.com/archive/cocoa/327153-webview-find-panel-bar-implementation.html y http://stackoverflow.com/questions/4601671/how-to-i-highlight-search-results-in-a-webview- like-safari-and-nstextview-showfi – Nickolay