Question

I am developing a custom PDF reader for ipad.I have taken a UIScrollView and adding/removing UIViews to it on which the equivalent thumbnail of corresponding pdf page will be displayed.I am creating an NSOperation and adding to a NSOperationQueue as soon as a UIView is added to the scroll view to generate PDF thumbnail in background.At any point of time there will be 3 UIViews on the scroll view.The whole arrangement is working fine with the small PDF files as they renders fast but the problem is with large/complex PDF pages,when ever user leaves navigation at a particular page, as per my implementation,there will be 3 NSOperations simultaneously working in the background to generate 3 thumbnails(one for previous page,one for current page and other for next page)thus taking long time,as a whole, to display the current page.I tried to iterate through all live NSOperation objects and set high priority to the one which is suppose to render the current page thumbnail in scrollViewDidEndDecelerating: method but its not working and the resulting effect is still same.Please suggest me a way to over come my problem, thanks in advance.

Was it helpful?

Solution

If you have set your NSOperationQueue to work in the background (i.e. you have not called [NSOperationQueue mainQueue]. The tasks should be completed asynchronously, but will not update the view which is running on the main thread until much later. The priority level does not matter as it does not relate to the thread in which the action takes place. The solution would be to add:

-(void)main {

    // ** load PDF image **

    [self performSelectorOnMainThread:@selector(insertImageLoaded:)
                            withObject:img
                        waitUntilDone:YES];

}

Basically, what you must remember is that iOS creates a small thread pool which is much more visible when using GCD that NSOperations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top