Reputation: 5510
I have an NSMutableArray of NSDictionaries that looks like this
<Blank BlankName="V6" Type="Line" CurrentType="Crypt"/>
<Blank BlankName="T3" Type="Ion" CurrentType="Crypt"/>
<Blank BlankName="HU" Type="Sia" CurrentType="Crypt"/>
<Blank BlankName="HF" Type="Ion" CurrentType="Crypt"/>
<Blank BlankName="HU5" Type="Sia" CurrentType="Crypt"/>
<Blank BlankName="HU6" Type="Sia" CurrentType="Less"/>
<Blank BlankName="V6" Type="Line" CurrentType="Less"/>
<Blank BlankName="V66" Type="Line" CurrentType="Less"/>
I am trying to figure out how to place it into a tree like structure to be displayed in a UITableView.
There will be 3 types of information, in this structure
Header (unique) - CurrentType
- Sub Header (unique) - Type
- Info (multiple items) - BlankName
So Using the xml I have as an example the UITableView would look something like this.
Crypt
- Ion
- T3
- HF
- Line
- V6
- Sia
- HU
- HU5
Less
- Line
- V6
- V66
- Sia
- HU6
I don't really have any sample code that I have been working on as I really don't know where to start on this, for instance if there is a specific structure suited for storing this type of information or not. I haven't looked into sorting because I have no clue about how it could be stored.
I am still reading and investigating after asking this question.
Upvotes: 1
Views: 583
Reputation: 2017
To create a flat array - change you parsing code to create an array like this:
[ <Dictionary containing Header 1 title, indentation 0>,
(Dictionary containing Sub-Header 1 title, indentation 1),
-Dictionary containing Sub-Header-info 1 title, indentation 2-,
-Dictionary containing Sub-Header-info 1 title, indentation 2-,
.....
(Dictionary containing Sub-Header 2 title, indentation 1),
.....
<Dictionary containing Header 2 title, indentation 0>,
.....
and so on.
]
Instead of Dictionary, you can create your own custom object class to hold values of indentation and title and other stuffs. will be easier to use :) Cheers :)
Upvotes: 1
Reputation: 62062
Ultimately, the easiest way to represent items in a UITableView
(in my opinion) is with a flat array (or an array of flat arrays if you have multiple sections).
What you need to do is increase the indentation level based on what level of the tree you're in, but you also need the correct order.
It might help to have an object that looks like this:
@interface MyObject
@property NSInteger level;
@property id object;
@end
Now, iterate through your XML. Set the level
property on this object to the correct depth the object is in the XML, and let object
be a pointer to the original object.
As you do this, throw all of these objects into an array and make sure you're getting the order right.
Once you've built the array, now just use it with the table view's data source.
For numberOfRows
, return the array's count.
When you're creating the table view cells, set the indentation level to the level
property you set in the container object.
Upvotes: 0