Results 1 to 3 of 3

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Create a dictionary property list programmatically

  1. #1
    Default Create a dictionary property list programmatically
    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

    Code:
    //keys
    
    NSArray *Childs = [NSArray arrayWithObjects:@"testerbet", nil];
    
    NSArray *Children = [NSArray arrayWithObjects:@"Children", nil];
    
    NSArray *Keys = [NSArray arrayWithObjects:@"Rows", nil];
    
    NSArray *Title = [NSArray arrayWithObjects:@"Title", nil];
    
    //strings
    
    NSString *Titles;
    
    Titles = @"mmm training";
    
    //dictionary 
    
    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

  2. #2
    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.

    Code:
    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; 07-14-2009 at 05:52 PM.
    Starlight Computer Wizardry
    Pocket-sized Development
    Follow me on twitter: @NetMage

  3. #3
    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.

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •