I need to use plist for data persistence. How can I store a value from a view controller into a plist and then display that value in a table view?

StackOverflow https://stackoverflow.com/questions/23193000

  •  06-07-2023
  •  | 
  •  

So when I click "View User Record" button I want to display whatever value of Score and Live of a view controller and store it in a plist as an array. And then those values from the plist will be displayed into the table view

有帮助吗?

解决方案

try this for adding value in plist file .

NSString* plistPath = nil;
NSFileManager* manager = [NSFileManager defaultManager];
if (plistPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Contents/Info.plist"]) 
{
    if ([manager isWritableFileAtPath:plistPath]) 
    {
        NSMutableDictionary* infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
        [infoDict setObject:[NSNumber numberWithBool:hidden] forKey:@"LSUIElement"];
        [infoDict writeToFile:plistPath atomically:NO];
        [manager changeFileAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] atPath: [[NSBundle mainBundle] bundlePath]];
    }
}

And This is for Get Value from plist file.

 NSBundle* mainBundle = [NSBundle mainBundle]; 

 

// Reads the value of the custom key I added to the Info.plist
    NSString *value = [mainBundle objectForInfoDictionaryKey:@"key"];

//Log the value
NSLog(@"Value = %@", value);

// Get the value for the "Bundle version" from the Info.plist
[mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];

// Get the bundle identifier
[mainBundle bundleIdentifier];

i hope this code is useful for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top