简体   繁体   English

iOS中具有表视图的数据层次结构

[英]Data Hierarchy with Table Views in iOS

I have possibly many nested list..For exampel 我可能有很多嵌套列表。

I have a list and contains some folders, when user tapped it, i show content of the folder in the same tableview.. and this content may has some folders also, can when user tapped it, it also shows the same in the tableview. 我有一个列表,其中包含一些文件夹,当用户点击它时,我在同一表格视图中显示该文件夹的内容..并且此内容可能也包含一些文件夹,当用户点击它时,它在表格视图中也显示相同的文件夹。

but each type of list of the tableview can be different. 但是tableview的每种列表类型可以不同。 For example, first folder's list is list of X class, but the second one can be Y class.. 例如,第一个文件夹的列表是X类的列表,但是第二个文件夹可以是Y类的列表。

I did something but it doesnt work properly in some cases. 我做了一些事情,但在某些情况下无法正常工作。 So I do not know how to solve this kind of nested list. 因此,我不知道如何解决这种嵌套列表。

as scheme, Folder 1-> (Folder X,Folder Y, Document 1, Document 2) if user tap folder X 作为方案,如果用户点击文件夹X,则文件夹1->(文件夹X,文件夹Y,文档1,文档2)

folder X -> (folder a, folder b) 文件夹X->(文件夹a,文件夹b)

but this list (Folder X,Folder Y, Document 1, Document 2) is class of X, like List this list (folder a, folder b) is class of Y like List 但是此列表(文件夹X,文件夹Y,文档1,文档2)是X的类,例如列表。此列表(文件夹a,文件夹b)是像列表一样的Y的类

because webservice send me like that.. 因为网络服务这样发送给我

I know that it is complicated but i hope it is clear. 我知道这很复杂,但我希望它很清楚。

I am using Xamarin.ios, but doesnt matter for objective-c. 我正在使用Xamarin.ios,但对于Objective-C来说并不重要。 I just seek for possible solution. 我只是在寻找可能的解决方案。 Like a generic list? 像一般清单一样?

1. Nested Lists: 1.嵌套列表:

In your view controller keep a list of the "selected objects" (it would behave as a stack). 在您的视图控制器中,保留“选定对象”的列表(它将表现为堆栈)。 When you select a cell, add that corresponding folder / document / ... object to the selectedObjects list/stack. 选择单元格时,将相应的文件夹/ document / ...对象添加到selectedObjects列表/堆栈中。 If you go back, remove the last element. 如果返回,请删除最后一个元素。 When showing objects for the table view, take the last entry in the list/stack and you know "where you are". 当显示用于表视图的对象时,获取列表/堆栈中的最后一个条目,您就会知道“您在哪里”。

A sample use case following your example: 遵循您的示例的示例用例:

  1. selectedObjects is empty selectedObjects为空
  2. Tap "Folder 1" in table view 在表格视图中点击“文件夹1”
  3. Add "Folder 1" to the end of selectedObjects 将“文件夹1”添加到selectedObjects的末尾
  4. Show the sub elements of "Folder 1" being Folder X,Folder Y, Document 1, Document 2 显示“文件夹1”的子元素,即文件夹X,文件夹Y,文档1,文档2
  5. Tap "Folder X" in table view 在表格视图中点击“文件夹X”
  6. Add "Folder X" to the end of selectedObjects (the list now has two entries "Folder 1" and "Folder X") selectedObjects的末尾添加“ Folder X”(列表现在有两个条目“ Folder 1”和“ Folder X”)
  7. Show the sub elements of "Folder X" being folder a, folder b 显示文件夹X,文件夹B的“文件夹X”的子元素
  8. Tap "Back" in table view 在表格视图中点击“返回”
  9. Remove the last entry from selectedObjects , now it contains only "Folder 1" selectedObjects删除最后一个条目,现在它仅包含“文件夹1”
  10. Get the last entry from selectedObjects which now is "Folder 1" selectedObjects获取最后一个条目,该条目现在是“文件夹1”
  11. You have the folder for which to show the sub list 您具有要显示子列表的文件夹

2. Different Classes: 2.不同的类别:

If there is no other way, you could create a base class - say - CellData . 如果没有其他方法,则可以创建一个基类,例如CellData Then for each different class which you get from your webservice, create a subclass - say - FolderCellData and DocumentCellData . 然后,对于从Web服务获得的每个不同的类,创建一个子类,例如FolderCellDataDocumentCellData Each of the subclasses holds a reference to the actual instance which you get from the web service. 每个子类都包含对您从Web服务获取的实际实例的引用。 Then you could use lists of CellData to hold references to class X and Y. 然后,您可以使用CellData列表来保存对类X和Y的引用。

There will be code which "decides" which of the CellData subclasses to use depending on the class from the webservice. 将有代码根据网络服务中的类“决定”要使用哪个CellData子类。 These decisions may as well be placed in the rendering (decide which UITableViewCell to use?) or in the user input handling (Which cell has been tapped -> which class is it in the list of objects?). 这些决定也可以放置在呈现中(决定使用哪个UITableViewCell ?)或用户输入处理中(在哪个单元格中被点按->它在对象列表中是哪个类?)。 So you may as well use a list of NSObject s anyway and save you from having to maintain a mirror class hierarchy for the webservices classes. 因此,您仍然可以使用NSObject的列表,从而不必为Webservices类维护镜像类层次结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM