views:

46

answers:

1

I am having trouble grasping the concept of multi component uipickerviews. I really would like to just OWN this subject. I would like to make a 4 component pickerview with components that are dependent on one another.

The first component is being populated from an array from my db, and that is showing up fine. I have all of the other info available in arrays, but I am just getting hung up on the dependent aspect of my pickerview. I figure the best way to make component 2's data depend on comp 1 is to link them somehow within the didSelectRow section. But I don't know the syntax.

I have been working at this for hours now and feel like I am really close, but I just need some help with a few issues. What is the syntax for connecting components so they depend on each other? Something like this? (Which is awful I know, but I am thinking that is the direction I need to get) :

if(picker = pickerComponent1)
     //set number of rows for comp2 and also the content etc...

Another issue is determining the numberOfRowsInComponent bit because they aren't in the same method...

If anyone knows about (or wants to give :) a tutorial on this subject, it would be so helpful! Or if you are knowledgeable on the topic and would like to share some of what you know, that would be perfect too. I would really like to see this seemingly simple task completed. Thanks in advance!

A: 

It's quite simple. In the pickerView:didSelectRow:inComponent: method, just call [myPicker reloadComponent:] for all components coming after the one where the selection changed. The picker will then automatically ask its datasource (your view controller, presumably) for the number of rows and the rows' values.

Then, in pickerView:numberOfRowsInComponent: and pickerView:titleForRow:forComponent:, return the appropriate values (the count and contents of the corresponding array) depending on the values of the parent components' selected rows.

Ole Begemann
It definitely seems quite simple in concept, however I am just spinning my wheels trying to get this setup. How do I dynamically return the appropriate values depending on the values of the parent components' selected rows? I am running into a chicken before the egg issue, and I just can't get my head around it. If you could further expound on this concept, it would be appreciated!!!!!
Jeff