iPad、类似 App Store 的界面、管理项目的建议
我正在尝试创建一个类似于 App Store 应用程序(iPad 设备)中呈现的用户界面。这是一种可滚动网格(水平滚动),其中每个元素都包含可在应用程序商店中销售的应用程序的概述(每个元素由图像、标题等组成)。我的目标是一样的。我有兴趣开发一个 UIScrollView,其中元素被排列和显示。每个 UI 元素都包含一个图像和一个描述。
从之前的考虑出发,我开发了一个 ItemViewController.h/.m 和相关的 .xib (ItemView.xib)。每个元素都可以响应点击等操作。 ItemViewController.m 管理此点击,因为它是其文件的所有者。使用 MainViewController.h/.m 类中的 initWithNibNamad 方法创建一个元素。此类包含 UIScrollView。然后,与该项目关联的视图被添加到 UIScrollView 中。
由于可能有多个项目,您能给我一些在 MainViewController 中管理 ItemViewController 项目的建议吗?我是否必须将对 ItemViewController 的每个引用存储在字典中(例如)?首先,我还考虑将 MainViewController 设置为 ItemView.xib 文件的所有者,但我认为管理项目的问题可能仍然存在。
先感谢您。我希望一切都清楚了。
I'm trying to create an user interface like the one is presented in App Store application (iPad device). This is a sort of scrollable grid (horizontal scroll) where each element consists in an overview of an application that can be selled in the app store (each element consist of an image, a title, and so on). My goal is the same. I'm interested in developing a UIScrollView where elements are arranged and displayed. Each UI element consists in a image and a description.
Moving from the previous considerations, I developed an ItemViewController.h/.m and the relative .xib (ItemView.xib). Each element can respond to actions like the tap. The ItemViewController.m manages this tap since it's its File's Owner. An element is created with initWithNibNamad method in the class MainViewController.h/.m. This class contains the UIScrollView. Then, the view associated with the item is added to the UIScrollView.
Since it's possible to have more than one item, could you give me some suggestions to manage the ItemViewController items in MainViewController? Do I have to store each reference to ItemViewController in a dictionary (for example)? In a first moment I also considered to set MainViewController as ItemView.xib File's Owner, but I think the problem for managing items could remain.
Thank you in advance. I hope it's all clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你的结构是倒退的。您不应该将界面呈现的项目存储在控制器中。您应该有一个模型,其中包含控制器用来构造界面视图的项目。
因此,您有一个包含产品列表及其关联元数据的模型。您的控制器查询该列表,为其中的每个项目构造一个视图,并将这些视图添加到应用程序的视图层次结构中(可能在滚动视图中,就像您建议的那样)。与这些视图的任何交互都会回调控制器,然后控制器对模型进行更改。对模型的任何更改都应该发布控制器侦听的通知,以便它知道适当地更新(或只是重新加载)其呈现的视图。
请注意,在这种安排中,模型中的一项可以在界面中多次表示。假设您要呈现一个标记为“巨人”的项目列表和一个标记为“绿色”的项目列表。如果您有“Jolly Green Giant”产品,它将出现在两个列表中。但由于模型中的同一项目是两者的源,因此对其中一项的任何更改都会自动反映在另一项中。这通常是所需的行为(如果您从“绿色”列表中删除了“Jolly Green Giant”,您还希望将其从“Giant”列表中删除)。
有关更多信息,请阅读模型视图控制器 (MVC) 模式。
It sounds to me like you have this structured backwards. You shouldn't be storing items presented in by the interface in your controller. You should have a model that contains your items that your controller uses to construct the views of your interface.
So you have a model containing a list of products and their associated metadata. Your controller queries that list, constructs a view for each item in it, and adds those views to the app's view hierarchy (maybe in a scroll view, like you suggest). Any interaction with those views calls back to the controller which then makes changes to the model. Any changes to the model should post a notification that the controller listens for so that it knows to update (or just reload) its presented views appropriately.
Note that in this arrangement, one item in your model can be represented in the interface multiple times. Say you're presenting a list for items tagged as "Giant" and a list for items tagged as "Green". If you had a "Jolly Green Giant" product, it would be represented in both lists. But because the same item in your model is the source for both, any changes to one is automatically reflected by the other. This is generally the desired behavior (if you deleted "Jolly Green Giant" from the "Green" list, you'd also want it to be deleted from the "Giant" list).
For more information, read up on the Model View Controller (MVC) pattern.
看看 AQGridView - 它应该能够满足您的需求。
Take a look at AQGridView - it should be more than capable of doing what you need.