Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6177773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:20:06+00:00 2026-05-24T00:20:06+00:00

In one hand, I’ve got a plist in witch the root key is an

  • 0

In one hand, I’ve got a plist in witch the root key is an array with 12 items.
In the second hand, i’ve got a sectioned tableview (with 3 sections MOTIF-COULEUR-OTHER)
What i want is that the tableview display correctly the datas in the sections.
in the first section i want to have items 0,1,2,3 of my plist
in the second section i want to have items 4,5,6,7,8,9,10 of my plist
in the last section i want to have the items 11 & 12

May be it’s really simple, but it just made me crasy

her’s my RootViewController.h & .m

the .h

//
//  RootViewController.h
//  FichesRaces
//
//  Created by a3116b on 28/05/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate> {
        NSArray *tabWebSites;


}

@property (nonatomic, retain) NSArray *tabWebSites;








@end

the .m

//
//  RootViewController.m
//  FichesRaces
//
//  Created by a3116b on 28/05/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "CatsList.h"
#import "DetailViewController.h"

@implementation RootViewController
@synthesize tabWebSites;







- (void)viewDidLoad {
    [super viewDidLoad];

    // Charger le fichier .plist dans un tableau que l'on appelera  arrayFromFile
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cats" ofType:@"plist"];
    NSDictionary *dictFromFile = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSArray *arrayFromFile = [dictFromFile objectForKey:@"Root"];

    // Créons un tableau temporaire que nous allons remplir avec un objet Website par NSDictionnary contenu dans le fichier .plist
    // Notez l'utilisation de NSEnumerator pour parcourir un tableau
    NSMutableArray *websitesToAdd = [[NSMutableArray alloc] init];
    NSEnumerator *enumerator = [arrayFromFile objectEnumerator];
    NSDictionary *anObject;
    while ((anObject = [enumerator nextObject])) {
        CatsList *cl = [[CatsList alloc] initWithDictionaryFromPlist: anObject];
        [websitesToAdd addObject: cl];
        [cl release];
    }

    // Remplir la propriété tabWebSites avec le contenu du NSMutableArray précédent
    self.tabWebSites = [NSArray arrayWithArray:websitesToAdd];

    // Gestion de la mémoire : pour chaque alloc, n'oubliez pas le release qui va avec !
    [websitesToAdd release];
    [arrayFromFile release];
}




- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}



- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if ( section == 0 ) return @"Les Motifs";
    if ( section == 1 ) return @"Les Couleurs";
    if ( section == 2 ) return @"Bon à Savoir";

    return @"";

   // return [sectionHeaders objectAtIndex:section];
}






// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 4;
            break;

        case 1:
            return 13;
            break;

        default:
            return 3;
            break;
    }

   }





// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    if (indexPath.section == 2) {
        CellIdentifier = @"cell";
    }


    // Les cellules sont mises en cache pour accélérer le traitement, sous l'identifiant "Cell",
    // on essaie récupère ce modèle de cellule s'il est déjà en cache
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Si on n'a pas réussi à sortir une cellule du cache, on crée un nouveau modèle de cellule
    // et on l'enregistre dans le cache
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];



     /*    (indexPath.section == 0 && indexPath.row ==0);
         (indexPath.section == 1 && indexPath.row == 5);
         (indexPath.section == 2 && indexPath.row == 13);*/

   /*     //-----------------------------------------------

        NSUInteger sectionNumber = [indexPath section];
        NSUInteger rowNumber = [indexPath row];  

        // determine the correct row.
        // it will be restarted from 0 every time, and as
        // we're just loading in from one array, we need to
        // offset it by the right amount depending on the section.
        //  int sectionNumber = indexPath.row;
        if ( sectionNumber == 0 ) rowNumber = 4;
        if ( sectionNumber == 1 ) rowNumber = +5;
        if ( sectionNumber == 2 ) rowNumber = +18;


        //-----------------------------------------------   */


    }





    // On récupère l'objet Website qui correspon à la ligne que l'on souhaite afficher
    CatsList *cl = [self.tabWebSites objectAtIndex:indexPath.row];

    // On configure la cellule avec le titre du site et sa description
    cell.textLabel.text = cl.TITLE;
    cell.detailTextLabel.text = cl.DESCRIPTION;


    //important ajouter signalisation sinon APP REFUSE

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    // On renvoie la cellule configurée pour l'affichage
    return cell;
}



/*- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 3) {
        return nil;
    }
    return indexPath;
}*/





- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{



    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    detailVC.CL = [self.tabWebSites objectAtIndex:indexPath.row];

    [self.navigationController pushViewController:detailVC animated:YES];
    [detailVC release];
}






- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc
{
    [super dealloc];
}

@end

Thanks, your answers are very useful for me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:20:07+00:00Added an answer on May 24, 2026 at 12:20 am

    You should tweak your data source (the NSArray you build from the plist) into managing the different sections you have. For example, instead of doing:

    // On récupère l'objet Website qui correspon à la ligne que l'on souhaite afficher
    CatsList *cl = [self.tabWebSites objectAtIndex:indexPath.row];
    

    you could do:

    CatsList *cl = [self.tabWebSites objectAtIndex:[self linearIndexFromIndexPath:indexPath]];
    

    where linearIndexFromIndexPath: would be defined, e.g., like this:

    - (NSUInteger)linearIndexFromIndexPath:(NSIndexPath*)indexPath {
        NSUInteger result = 0;
        for (int i = 0; i < indexPath.section ; i++) {
             result += [self numberOfSectionsInTableView:self.tableView];
        }
        return result + indexPath.row;
    }
    

    or something similar. Notice that in my implementation, I decided not to hard code the number of rows in each section, but of retrieving them using the delegate method. This makes the code more complex, but more resilient to changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On the one hand; String first = thing; String second = thing; if(first ==
On one hand it is easy to see given a key function, one can
In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and
I have a Coda slider on one webpage (hand-crafted, not using the plugin, but
I'm writing a 7 card poker hand evaluator as one of my pet projects.
On one hand, I know that the advisable usage of Properties is to have
On the one hand there is http://ckfinder.com/ CKFinder or the people behind it have
im messing with the encodings. For one hand i have a url that is
i encounter an issue with my application. On one hand when my app launches,
On the one hand, I hear people saying that the two keys are totally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.