Setting imagePickerPopover to nil, why?


#1

Hi, in the popoverControllerDidDismissPopover we set imagePickerPopover to nil. My question is why??

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController { NSLog(@"User dismissed popover"); imagePickerPopover = nil; }


#2

quote from page 266:

“When you explicitly send the message dismissPopoverAnimated: to dismiss the popover controller, it does not send popoverControllerDidDismissPopover: to its delegate, so you must set imagePickerPopover to nil in dismissPopOverAnimated:.”

and from page 265:

“Notice that you set imagePickerPopover to nil here to destroy the popover. You will create a new one each time the camera button is tapped.”

From what I understand, you only want one instance imagePickerPopover to ever exist. Setting imagePickerPopover to nil when you dismiss it ensures that you will only have one instance of it and not a collection of them in memory each time it is presented/dismissed from the screen.