Re: setting selection in PDFView
Re: setting selection in PDFView
- Subject: Re: setting selection in PDFView
- From: Antonio Nunes <email@hidden>
- Date: Fri, 20 Jul 2012 19:22:50 +0100
On 20 Jul 2012, at 18:26, Martin Hewitson wrote:
>>> In my app I have a user action which allows them to select a particular line in a PDFView. The relevant method (on my PDFView subclass) looks like this.
>>>
>>> - (void)displayLineAtPoint:(NSPoint)point inPageAtIndex:(NSUInteger)pageIndex
>>> {
>>> if (pageIndex < [[self document] pageCount]) {
>>> [[self window] makeFirstResponder:self];
>>> PDFPage *page = [[self document] pageAtIndex:pageIndex];
>>> PDFSelection *sel = [page selectionForLineAtPoint:point];
>>> [self performSelectorOnMainThread:@selector(goToPage:) withObject:page waitUntilDone:YES];
>>> [self setCurrentSelection:sel];
>>> [self scrollSelectionToVisible:self];
>>> [self display];
>>> [self setCurrentSelection:nil];
>>> [self performSelector:@selector(setCurrentSelectionAndAnimate:) withObject:sel afterDelay:0.2];
>>> }
>>> }
>>
>> [self performSelectorOnMainThread:@selector(goToPage:) withObject:page waitUntilDone:YES];
>>
>> looks suspicious. If you're doing this on a secondary thread (which this line implies), I'm pretty sure that at least the call to -makeFirstResponder: is illegal (main thread only). Not sure about the PDF document class.
>
> No, it's all done on the main thread. Actually, using performSelectorOnMainThread... was just an attempt to get the thing to behave properly. Nominally I'm just calling -setCurrentSelectionAndAnimate: directly. The results are the same.
goToPage: will scroll the shortest distance that shows as much of the page as possible, so it might not even show the whole page and hence, possibly, not the selection. You might want to create a destination (to page and point) and then use goToDestination: to go there. It offers greater precision, and ensures point will always be visible.
Also: is "setCurrentSelectionAndAnimate" a method of your own? PDFView has setCurrentSelection:animate:
-António
----------------------------------------------------
A merry heart does good like medicine
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden