我有一个mac cocoa应用程序,其中包含一些包含一些文本的webview.我想使用NSTextFinder提供的默认查找栏搜索该文本.虽然这看起来很容易通过NSTextFinder类引用读取,但我无法显示查找栏.我错过了什么?
作为旁注:
- 是的,我尝试将findBarContainer设置为不同的视图,同样的事情.我回到滚动视图以消除调试的复杂性
- 调用performTextFinderAction来执行查找操作
**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 …
Run Code Online (Sandbox Code Playgroud) 我有一个内容可编辑的 div,其中包含一些 html 元素。例如,假设我有:
<div contenteditable="true" id="myTextArea">
Some content, <div id="div1">content in div</div>,
and more <span id="span1">content</span></div>
Run Code Online (Sandbox Code Playgroud)
当用户在 myTextArea 中编辑文本并删除一些 html 元素(通过粘贴新内容或只是退格文本)时,我希望每个 html 元素触发一个事件并告诉我它已被删除。关于我如何做到这一点的任何想法?