UIPickerView委托和数据源的职责划分
我正在学习 UIPickerView 以及它的某些方法如何在委托中处理以及如何在数据源中处理。
委托处理的方法:
绘制项目矩形的方向, pickerView:titleForRow:forComponent 行值(字符串或视图)
数据源处理的方法:
组件数量, pickerView:numberOfRowsInComponent, numberOfComponentsInPickerView
问题: 有没有一种简单的方法来记住哪些方法由委托处理,哪些方法由数据源处理? 为什么有些 UIPickerView 方法由委托处理,有些由数据源处理,为什么它们以这种方式在两者之间划分?
提前致谢。
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 datasource?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIPickerView 和 UITableView 在支持委托和数据源对象方面具有非常相似的设计。委托对象通常处理用户与选择器/表的交互(或用户交互的结果),而数据源对象,顾名思义,提供选择器/表视图的规范和内容。
在实践中,您通常将包含的 UIViewController 设为委托和数据源,并在视图控制器中实现两组协议方法。
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.