0

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)

CoolDocMan
  • 637
  • 7
  • 29
  • Sorry the delegate part did not show. Here are the delegates I have implemented @interface WelcomeViewController : UIViewController – CoolDocMan Sep 24 '12 at 00:32

1 Answers1

1

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

Codezy
  • 5,540
  • 7
  • 39
  • 48
  • Yes I checked and I have set this... I have these two propertoes of WelcomeViewController UIPopoverController *locationPopoverController; UIPickerView *locationPickerView; – CoolDocMan Sep 24 '12 at 01:04
  • And I set these in WelcomeViewController's viewDidLoad. But it still does not work. I think the way I have set up the UIPopoverController may have a part to play but I am not sure what the correct way is... – CoolDocMan Sep 24 '12 at 01:15
  • But did you do this: locationPickerView.delegate = self; and locationPopoverController.delegate = self; // or in interface builder – Codezy Sep 24 '12 at 14:53
  • thanks for the response Codezy - I did that as well - set those in WelcomeViewCOntroller. But the delegate functions for some reason do not get called when the picker is launched with a popoverVC. – CoolDocMan Sep 25 '12 at 16:47
  • I'll admit I was confused about how exactly to get them to work together and there was obviously something wrong in the way I had that setup ... so the question is how would I create a UIPopoverController with a UIPickerView inside it and launch them together from WelcomeViewController? What should the parent child view hierarchy be for that to ensure that the delegate functions get called. When I tried to do that the picker delegate functions were not getting called so I finally implememnted without the popover (not ideal but it works - more details on that above) – CoolDocMan Sep 25 '12 at 16:47
  • Well thats a bit more involved question. An example of that is here: http://stackoverflow.com/questions/7341835/uidatepicker-in-uipopover – Codezy Sep 26 '12 at 21:58