为什么选择器需要数据源?
据我了解,Pickers 有一个 Delegate 类。 为什么需要额外的数据源?
As I understand, Pickers have an Delegate class. Why's there an additional Datasource needed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
委托和数据源之间存在差异。
数据源通常用于配置控件显示的内容。 “你有多少行?”,“我应该在这一行显示什么”,等等。
委托通常用于让控制代码知道发生了一些事情。 “嘿,有人选择了这一行。”,“嘿,有人开始编辑这一行。”
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."
因为选择器视图需要有关如何填充每个段内的表的信息。
有时,让一个类处理数据的来源,让另一个类处理如何处理数据可能会很有用(MVC 模式)
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)
像大多数主管一样,挑选员很愚蠢。 它不知道要做什么,所以它不断地被给予数据和任务(由提供者); 但它需要有人知道如何处理它。 这就是代表。
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.
API 用于将数据源和委托方法组合到一个协议中(至少对于 UITableViews 而言),但它不灵活 - 现在您可以让一个完全不同的对象提供要从负责处理数据的代码中显示的数据。使用选择器的机制。
一般来说,您最终会将两者连接到同一个对象。
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.