Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, you need to use arrays for the top two levels of your data structure. Dictionaries are unordered so that makes it hard to use them as the data source for a table's format. It's fine to use them for the data for each record displayed in an individual cell. To use the dictionaries as table format data, you have to store their keys to an array so that every key has a specific numerical index that the table can use to find the key.</p> <p>You will need something like the following in your UITabelViewDataSource class:</p> <pre><code>@property(nonatomic, retain) NSArray *sectionNames; ... NSArray *sectionNames=[teams allKeys]; </code></pre> <p>In your UITabelViewDataSource class you would need these methods:</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [self.sectionNames count]; } </code></pre> <p>This returns the number of sections in the table which in your case represents the number of objects in your top level dictionary. </p> <pre><code>- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{ return [[teams valueForKey:[self.sectionNames objectAtIndex:section] count]; } </code></pre> <p>This returns the number of rows within each section which in your case means the number of objects in each second level dictionary returned for the key stored in each sectionName element. </p> <pre><code>- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return [self.sectionNames objectAtIndex:section]; } </code></pre> <p>This returns the name that will be displayed for each section header which in your case is the key for each first level dictionary value. </p> <p>Unless you have a specific need to reference the sections by key, you should think about storing everything except the team data in arrays instead of dictionaries. It will make you tables easier to implement. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload