简体   繁体   English

如何编写字典对象的 plist 数组..动态并填充表格视图

[英]how to write plist array of dictionary objects..dynamically and populating the tableview

m working with plist and i am new to it.. I want to save two type of values,these two are labels,ie我正在使用plist ,我是新手。我想保存两种类型的值,这两个是标签,即

label1 label2 label1 label2

so for that i tried to write the code but was able to save only for one label ie label1 ..in a plist and then populate it into the table so i got one value on cell.textlabel.text = label1.text因此,为此我尝试编写代码,但只能保存一个 label 即label1 ..在 plist 中,然后将其填充到表格中,因此我在cell.textlabel.text = label1.text上得到一个值

but i need this also..但我也需要这个..

cell.detailedlabel.text = label2.text

so below is my code.. to save label1.text所以下面是我的代码.. 保存label1.text

-(IBAction) myBrand:(id) sender
{
     NSLog(@"mylist  Clicked");    
    NSMutableArray *array = [[NSMutableArray alloc] init];

    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,      NSUserDomainMask, YES);

NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];    

    NSString *plistPath = [docsDir stringByAppendingPathComponent:@"Data.plist"];


    [array addObjectsFromArray:[NSArray arrayWithContentsOfFile:plistPath]];
    [array addObject:searchLabel.text];

    [array writeToFile:plistPath atomically: TRUE];    
}

now if i want o save one more label..in the array and populate it on cells detailedlabel..how shall i proceed..please help me out..现在,如果我想再保存一个 label..在数组中并将其填充到单元格详细标签上..我应该如何继续..请帮帮我..

Hi friends..I want o have something like this....嗨朋友们..我想要像这样的东西....

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 addObject:entity];
        [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]];   

Regards Ranjit问候兰吉特

go through the portion of the code below which will solve your problem of storing both label values in plist... go 通过下面的代码部分将解决您在 plist 中存储两个 label 值的问题...

NSMutableArray *data = [[NSMutableArray alloc] init];

NSMutableDictionary* newDict = [[NSMutableDictionary alloc] init];
[newDict setValue:label1.text forKey:labell];    //forKey identify the name of the array element in dictionary for plist
[newDict setValue:label2.text forKey:label2];

[data addObject:newDrink];
[newDict release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM