在Cocoa Mac Os X Objective-C应用程序中,如何在PDFView当前显示的pdf页面中实现搜索?
我在Cocoa应用程序中搜索PDFView时遇到问题。现在,我已经设置了一个iAction,其中包含用于选择特定单词(“continue”)的代码,我知道该单词驻留在我测试的当前pdf页面中。尽管我的代码正确地收集了PDFSelection对象数组,但从未选择该词,只找到一个匹配项。我的代码是:在Cocoa Mac Os X Objective-C应用程序中,如何在PDFView当前显示的pdf页面中实现搜索?,objective-c,cocoa,pdf,quartz-graphics,Objective C,Cocoa,Pdf,Quartz Graphics,我在Cocoa应用程序中搜索PDFView时遇到问题。现在,我已经设置了一个iAction,其中包含用于选择特定单词(“continue”)的代码,我知道该单词驻留在我测试的当前pdf页面中。尽管我的代码正确地收集了PDFSelection对象数组,但从未选择该词,只找到一个匹配项。我的代码是: -(IBAction)sampleAction:(id)sender { NSArray *results = [self.pdfView.document findString:@"continu
-(IBAction)sampleAction:(id)sender
{
NSArray *results = [self.pdfView.document findString:@"continue" withOptions:NSCaseInsensitiveSearch];
for (PDFSelection *pdfSel in results)
{
[pdfSel drawForPage:self.pdfView.currentPage active:YES];
}
[self.pdfView scrollSelectionToVisible:self];
}
尽管如此,在当前显示的页面中,单词continue仍然存在,但我没有选择。请帮忙 尝试使用以下命令查找下一个事件:
PDFSelection *pdfSel=[self.pdfView.document findString: @"continue"
fromSelection: self.pdfView.currentSelection
withOptions: NSCaseInsensitiveSearch];
if (pdfSel != nil)
{
[self.pdfView setCurrentSelection: pdfSel];
[self.pdfView scrollSelectionToVisible: self];
}
尝试使用以下命令查找下一个匹配项:
PDFSelection *pdfSel=[self.pdfView.document findString: @"continue"
fromSelection: self.pdfView.currentSelection
withOptions: NSCaseInsensitiveSearch];
if (pdfSel != nil)
{
[self.pdfView setCurrentSelection: pdfSel];
[self.pdfView scrollSelectionToVisible: self];
}
尝试设置PDFView的当前选择。非常感谢!这似乎奏效了!尝试设置PDFView的当前选择。非常感谢!这似乎奏效了!