开发者

Division of responsibility for UIPickerView delegate and datasource

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜