I have a UIButton that is linked to some code that invokes UIPrintInteractionController to print a PDF document.
If I tap the button, the view pops up to let me select a printer and then print the document. However, if I tap outside the view to dismiss the popup, and then quickly tap the “Print” button again, I get the following crash:
[NSConcreteData respondsToSelector:]: message sent to deallocated instance 0xa4696d0
I have debugged with NSZombies enabled, and the crash occurs at this line:
printController.printingItem = dataToPrint;
dataToPrint is instantiated in the same method but prior to this printController line:
NSData *dataToPrint = [NSData dataWithContentsOfFile:pdfFileName];
This crash only occurs if I tap quickly, if I give it a second, everything goes smoothly.
Anyone have any idea what this could be?
Make ‘dataToPrint’ a strong ivar, and only nil it when you are 100% sure it won’t be used again. Most likely the ‘printController.printingItem’ retains it, but when you dismiss the popup it gets released before the ‘Print’ button is hit again.