Corona中文站

强大、易学的跨平台(iOS/Android)开发框架。QQ群1:74390406(满) 群2:221929599

导航

objective-c简单的读写文件方法
====.h文件======


#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"];}
<< 使用uilabel实现跑马灯效果objective-c利用钥匙串,在应用里保存用户密码的方法 >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Walle Build 100427 Copyright 2011-2015 BuildApp.Net. All Rights Reserved.