开发者

How to work with Dictionary of arrays in plist on iphone

开发者 https://www.devze.com 2023-03-27 06:09 出处:网络
I am working with dictionary of arrays. I want to save two values at index 0 in the plist. I 开发者_如何学运维want to save a name and city names which appear on a label dynamically when a user clicks

I am working with dictionary of arrays. I want to save two values at index 0 in the plist. I 开发者_如何学运维want to save a name and city names which appear on a label dynamically when a user clicks on a button, and then later i want to show it in a tableview by using

  1. cell.textlabel.text
  2. cell.detailedtextlabel.text..

I have tried some code with the knowlege i have:

-(IBAction) myBrand:(id) sender
{
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // get paths from root direcory
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);

    // get documents path
    NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];    // get the path to our Data/plist file
    NSString *plistPath = [docsDir stringByAppendingPathComponent:@"Data.plist"];

    //This copies objects of plist to array if there is one
    [array addObjectsFromArray:[NSArray arrayWithContentsOfFile:plistPath]];

    [array insertObject:entity atIndex:0];
   [array insertObject:category atIndex:0];

    NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: entity, category, nil] forKeys:[NSArray arrayWithObjects: @"Entity", @"Category", nil]];   

    [plistDict writeToFile:plistPath atomically: TRUE];    
}

So friends, please help me out on how to proceed further.

Regards, Ranjit


You'll probably want to use CoreData to save the data and an NSFetchedResultsController with a table to display them. It isn't reasonable to go through the whole process here, as tutorials are available and Xcode includes a template for a table backed by the NSFetchedResultsController. Here are two tutorials that should get you started:

http://cocoadevcentral.com/articles/000085.php

http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号