User Tag List

  1. ulquiorra's Avatar
    Hello all ,

    I seem to be a little stuck on the creating propertly list issue( I'm new with iPhone development so bear with me ;-) ).
    I want to create a dictionary which feeds data to my uitableview but I seem to be getting some hard luck.
    I want to create a dictionary that resembles this one ( give or take a couple of items less )

    ItemFour.jpg (image)

    I've looked at this tutorial
    Property List Programming Guide: Creating Property Lists Programmatically

    and I came up with a small sample of my own

    NSArray *Childs = [NSArray arrayWithObjects:@"testerbet", nil];
    NSArray *Children = [NSArray arrayWithObjects:@"Children", nil];
    NSArray *Keys = [NSArray arrayWithObjects:@"Rows", nil];
    NSArray *Title = [NSArray arrayWithObjects:@"Title", nil];
    NSString *Titles;
    Titles = @"mmm training";
    NSDictionary *item1 = [NSDictionary dictionaryWithObject:Childs, Titles forKey:Children , Title];
    NSDictionary *item2 = [NSDictionary dictionaryWithObject:Childs, Titles forKey:Children , Title];
    NSDictionary *item3 = [NSDictionary dictionaryWithObject:Childs, Titles forKey:Children , Title];
    NSArray *Rows = [NSArray arrayWithObjects: item1, item2, item3, nil];
    NSDictionary *Root = [NSDictionary dictionaryWithObject:Rows forKey:Keys];
    // NSDictionary *tempDict = [[NSDictionary alloc] //initWithContentsOfFile:DataPath];
    NSDictionary *tempDict = [[NSDictionary alloc] initWithDictionary: Root];
    it's obvious that i'm trying to use this data of hierachy for my tableviews..
    I'm actually using this example

    Drill down table view with a detail view - iPhone SDK Articles

    So I was wondering how can I can create my propertylist( dictionary ) programmatically so that I can fill it with my own arrays.

    those of you who read it thnx in advance
    2009-07-14 04:02 PM
  2. NetMage's Avatar
    You seem to be creating some unnecessary arrays to me - if you are passing arrays of keys and objects, you need to use dictionaryWithObjects:forKeys: to create Root and when creating the items.

    Also, to create an array dynamically, you need to use an NSMutableArray.

    NSMutableArray *Rows = [NSMutableArray arrayWithCapacity: 1];
    for (int i = 0; i < 4; ++i) {
      NSMutableArray *theChildren = [NSMutableArray arrayWithCapacity: 1];
      [theChildren addObject: [NSString stringWithFormat: @"tester %d", i]];
    NSString *aTitle = [NSString stringWithFormat: @"Item %d", i];
      NSDictionary *anItem = [NSDictionary dictionaryWithObjectsAndKeys: aTitle, @"Title", theChildren, @"Children"];
      [Rows addObject: anItem];
    NSDictionary *Root = [NSDictionary withObject: Rows andKey: @"Rows"];
    Last edited by NetMage; 2009-07-14 at 11:52 PM.
    Starlight Computer Wizardry
    Pocket-sized Development
    Follow me on twitter: @NetMage
    2009-07-14 11:50 PM
  3. ulquiorra's Avatar
    Thnx a lot man..

    Your sample also looks pretty dynamic which is actually what I want.
    I want the number of tableview rows ( nodes ) to be dynamic as well and your sample just does that. I'm going to try and check it out asap and let you know how it went.
    2009-07-15 10:23 AM