Am learning about UIPickerView and how it some methods are handled in delegate and some in datasource.
Methods handled by delegate:
Directions for drawing rectangles for items, pickerView:titleForRow:forComponent Row values (strings or views)
Methods handled by datasource:
Number of components, pickerView:numberOfRowsInComponent, numberOfComponentsInPickerView
Questions: Is there an easy way to remember which methods are handled by delegate and which are handled by data开发者_开发技巧source? Why are some UIPickerView methods handled by delegate and some by datasource, and why are they divided between the two that way?
Thanks in advance.
UIPickerView and UITableView share a very similar design in terms of having supporting delegate and datasource objects. The delegate object usually handles user interaction (or the consequence of user interaction) with the picker/table, while the datasource object, as the name might suggest, provides the specifications and content of the picker/table view.
In practice, you typically make the containing UIViewController both the delegate and the datasource and implement both sets of protocol methods in the view controller.
精彩评论