UIPrinterPickerController crashes when popping with a UINavigationController parent

Originator:matt.fitzgerald
Number:rdar://18203215 Date Originated:September 2, 2014
Status:Open Resolved:No
Product:iOS Product Version:8.0 beta 5
Classification: Reproducible:Yes
 
Summary:
When using a UIPrinterPickerController to select a printer, and giving it a navigation controller (in this case self.navigationController) as the parent through printerPickerControllerParentViewController:, after selecting a printer and then popping one more, the app will crash attempting to reference a deallocated UIPrinterPickerViewController instance.  This also happens when, after having selected a printer, a different view controller is pushed to the navigation stack.

The app crashes due to calling [UIPrinterPickerViewController respondsToSelector:] on a deallocated object.

The issue is due to the fact that the UIPrinterPickerViewController becomes the delegate of the navigation controller, but that delegate is not removed when deallocating.  Thus, when another delegate method is fired after the printer picker has been dismissed, it crashes checking if the deallocated object responds to that delegate method.  The printer picker needs to be the navigation controller's delegate in order to fire the completion block.

A temporary fix is to nil out the navigation controller delegate yourself.  This can be done in the UIPrinterPickerControllerDelegate as such:

-(void)printerPickerControllerDidDismiss:(UIPrinterPickerController *)printerPickerController {
    self.navigationController.delegate = nil;
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!