Reputation: 155
I have built an app using the IOS 9 SDK.
I am printing using the UIPrintInteractionController and a subclass of UIPrintPageRenderer.
When the print dialog is displayed on the iPad or iPhone, UIPrintPageRenderer's drawPageAtIndex:inRect method is not called and the preview area on the dialog is just a gray box with a button that says Page 1.
This is an app that was originally written in the IOS 6 era and I am trying to update it for IOS 9, so perhaps I need to improve something.
Does anyone know what is happening here?
Thanks!
Upvotes: 3
Views: 1138
Reputation: 155
Turns out I was missing the numberOfPages override in the UIPrintPageRenderer derived class. The preview works after adding this override.
I'm giving carchase an upvote since the post tangentially mentioned the numberOfPages method, but my actual problem was not as subtle as suggested by carchase's post ;-).
Upvotes: 3
Reputation: 171
It sounds like you need to add the print formatter.
[myRenderer addPrintFormatter:viewFormatter startingAtPageAtIndex:0];
Upvotes: 0
Reputation: 41
I don't understand what's happening exactly, but I had the same problem and fixed it by
1) ensuring that logic in my overrides is being executed on the UI thread
2) moving my AddPrintFormatter call to the constructor method instead of calling from a NumberOfPages override (which allowed me to delete this override property).
There seems to be some weird threading behavior now when overriding UIPrintPageRenderer (at least in Xamarin's implementation).
For example, adding this simple override causes a UIKit Consistency error for me:
public override nint NumberOfPages
{
get
{
return base.NumberOfPages;
}
}
So it seems the base method begins execution on the UI thread when there isn't an override, but the subclass's override begins execution on a worker thread.
The iOS9 SDK Release Notes document says:
"Apps that subclass UIPrintPageRenderer or UIPrintFormatter to draw content for printing must be built with the iOS 9 SDK for the preview to display. The behavior of UIPrintPageRenderer has been updated to call drawPageAtIndex:inRect: multiple times with potentially different page sizes and margins. Various methods on UIPrintPageRenderer may be called from a non-main thread, but never from multiple threads concurrently."
Upvotes: 4