Search code examples
iphonedelegatesuipickerviewuipopovercontroller

UIPickerView in a Popover - didSelectRow not getting called


I have a ViewController for my app which has a single button which, when clicked, I need to show a popup view to allow the user to select from a list of addresses.

I've implemented the ViewController as follows:

@interface WelcomeViewController : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource, UIPopoverControllerDelegate>

And I've implemented the necessary delegate functions for the picker. I see the popup appear and display the UIPickerView inside it with the addresses correctly populated. The popup also disappears when I pick outside its frame - so that part appears to be working right.

However the picker just does not respond to picks (it does nothing!) - and in the debugger I see that didSelectRow is not getting called.

I have tried everything I can think of! Any help and advice would be appreciated!

9/24 UPDATE: I got this working but had to sacrifice using the Popover ViewController so it is not an ideal solution. I did it as follows:

  1. Created a UIPickerView for the addresses and added it as a subview of WelcomeViewController
  2. Implemented the following UIPickerViewDelegate functions in WelcomeViewController - numberOfComponentsInPickerView, numberOfRowsInComponent, didSelectRow, titleforRow and also set the delegate and datasource properties of the pickerview to self (ie the WelcomeViewController)

This works now, the downside of this implementation is that the address picker does not disappear when I pick outside the pickerview's frame (I imagine this is because it is not inside a popoverviewcontroller) I worked around this by setting the hide property on the pickerview when the user performs the next action. I have read about a better workaround in Stackoverflow where the entire background was a part of one big button - and I may resort to that if I cant find a way to get the picker inside a popup)


Solution

  • If you have not already you also set the picker delegate property to be your instance of WelcomeViewController