tags:

views:

436

answers:

4

As I understand, Pickers have an Delegate class. Why's there an additional Datasource needed?

+1  A: 

Because the picker view needs information on how to populate the table inside each segment.

Sometimes it may be useful to have one class handling where the data comes from and another handling what to do with it (MVC pattern)

rpetrich
+5  A: 

There is a difference between a delegate and a datasource.

A datasource is typically used to configure what is displayed by a control. "How many rows do you have?", "What should i display in this row", etc.

A delegate is usually used to let the controlling code know that something happened. "Hey someone selected this row.", "Hey someone started editing this row."

Lounges
+1  A: 

Like most supervisors, the picker is stupid. It can't figure out what to work on, so it keeps being given data and tasks(by the provider); but it needs to have someone who knows what to do with it. That's the delegate.

le dorfier
A: 

The API used to combine datasource and delegate methods into one protocol (at least for UITableViews), but it's inflexible - the way it is now you can have a totally different object provide the data to be displayed from the code that is responsible for handling the mechanics of using a picker.

Generally though you do end up wiring both to the same object.

Kendall Helmstetter Gelner