#import
@interface MyDataTestViewController : UIViewController {
NSDictionary *dicData;
IBOutlet
UILabel *lblName;
}
@property (nonatomic, retain) NSDictionary *dicData;
- (void) ReadData;
- (BOOL)SaveData;
@end
======.m文件=======
#import "MyDataTestViewController.h"
@implementation MyDataTestViewController@synthesize dicData;
- (void) ReadData{
NSString *Path = [[[[NSBundle
mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingFormat:@"/Documents/"];
NSString *LastPath = [Path stringByAppendingFormat:@"Data.plist"];
if (dicData != nil){
[dicData
release];
dicData = nil;
}
dicData = [[NSDictionary
alloc] initWithContentsOfFile:LastPath];}
- (BOOL)SaveData{
NSString *Path = [[[[NSBundle
mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingFormat:@"/Documents/"];
NSString *LastPath = [Path stringByAppendingFormat:@"Data.plist"];
BOOL isSuccess = [dicData writeToFile:LastPath atomically:YES];
if(isSuccess == YES)
{
return
YES;
}else {
return
NO;
}}
- (void)viewDidLoad { [super
viewDidLoad];
//dicData = [[NSDictionary alloc] initWithObjectsAndKeys:@"army",@"username",nil];
//[self SaveData];
[self
ReadData];
lblName.text = [dicData
objectForKey:@"username"];}