UITableView sectionné provenant d'une list pList

Je n'arrive pas à find un tutoriel facile à comprendre pour avoir un UITableView sectionné qui obtient ses données à partir d'un file pList.

Les choses qui me posent problème, c'est comment structurer correctement le file pList pour répondre à 2 sections différentes.

La racine du plist devrait être un tableau. Le tableau doit contenir deux dictionarys (vos sections). Les dictionarys contiendront deux keys: une pour le titre de la section et une pour les lignes de la section.

En supposant que vous avez lu votre plist dans une section NSArray *, vous pouvez returnner la section, le nombre de lignes, le titre de section et les titres de cellule en utilisant le code ci-dessous.

Votre file plist ressemblerait à ceci:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>Title</key> <ssortingng>Section1</ssortingng> <key>Rows</key> <array> <ssortingng>Section1 Item1</ssortingng> <ssortingng>Section1 Item2</ssortingng> </array> </dict> <dict> <key>Title</key> <ssortingng>Section2</ssortingng> <key>Rows</key> <array> <ssortingng>Section2 Item1</ssortingng> <ssortingng>Section2 Item2</ssortingng> </array> </dict> </array> </plist> #import "RootViewController.h" @interface RootViewController () @property (copy, nonatomic) NSArray* tableData; @end @implementation RootViewController @synthesize tableData; - (void) dealloc { self.tableData = nil; [super dealloc]; } - (void) viewDidLoad { [super viewDidLoad]; self.tableData = [NSArray arrayWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"Table" ofType: @"plist"]]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; { return [tableData count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; { return [[[tableData objectAtIndex: section] objectForKey: @"Rows"] count]; } - (NSSsortingng *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; { return [[tableData objectAtIndex: section] objectForKey: @"Title"]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { static NSSsortingng *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row]; return cell; } @end