如何跟踪视图所表示的数据?
我试图更好地在新项目中将数据和数据的可视化表示分开,但我在抽象方面遇到了一些问题。
我有一个集合中的对象列表,它们是库存的一部分,我使用该数据生成一些放置到界面中的 UIImageView,从而使我的模型和视图保持分离。当用户点击 UIImageView 时,我希望能够对集中的数据执行操作并修改相应的视图。
如何跟踪 UIImageView 所表示的对象?我认为存在某种机制,通过它我可以说“这是对您所代表的对象的引用”,但我无法弄清楚它是否存在,或者是否有更可接受的方法来实现视图/模型分离。
I'm attempting to do a better job of keeping my data and my visual representation of data separate in a new project and I'm having some trouble with the abstraction.
I have a list of objects in a set that are part of an inventory and I use that data to generate some UIImageViews that get placed into the interface, thus keeping my models and views separate. When a user taps on the UIImageView, I want to be able to take an action on the data in the set as well as modifying the corresponding view.
How do I keep track of the object that is being represented by the UIImageView? I would think there's some sort of mechanism by which I can say "here's a reference to the object that you represent" but I can't figure out if that exists or if there's a more accepted way to achieve the view/model separation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建作为 ImageView 扩展的对象,并在该视图初始化时,将视图中的属性关联到与该视图关联的数据。
you could create and object that is an extension of the ImageView and upon initialization of that view, associate a property in the view to your data associated with the view.