ios开发属性列表例子



//前面有部分参考别人的代码

-(NSString *)dataFilePath
{
    

{
    
/* 常量 NSDocumentDirectory 表明我们正在查找 Documents 目录路径,第二个常量 NSUserDomainMask 表示的是把搜索范围定在应用程序沙盒中, YES 表示的是希望希望该函数能查看用户主目录 */
    
    
NSArray  *paths =  NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory NSUserDomainMask YES );
    
//   数组索引 0 Documentd 目录,
    
NSString  *documentDirectory = [paths  objectAtIndex : 0 ];
    
//     返回一个 kFileName 的完整路径
    
return  [documentDirectory  stringByAppendingPathComponent : @"mylist.plist" ]; // 写自己喜欢的名字
}
- (
void )viewDidLoad
{
    [
super   viewDidLoad ];
    
    
    
//   检查数据文件是否存在,不存在则不加载
    
}

- (
void )didReceiveMemoryWarning
{
    [
super   didReceiveMemoryWarning ];
    
// Dispose of any resources that can be recreated.
}

- (
IBAction )reshai:( id )sender {
    [
IDtest   resignFirstResponder ];
}
- (
IBAction )res:( id )sender {
    [
NameText   resignFirstResponder ];
}


- (
IBAction )save:( id )sender {
    
    
NSString  *filePath = [ self   dataFilePath ]; // 调用前面的方法
    
    
NSMutableArray  *array=[[ NSMutableArray   alloc ] init ];
    
    
    [array 
addObject : IDtest . text ];
    [array 
addObject : NameText . text ];
    
    
    [array 
writeToFile :filePath  atomically : YES ];
    
     }

  
    
    
    


- (
IBAction )load:( id )sender {
    
    
NSString  *filePath = [ self   dataFilePath ];
    
if  ([[ NSFileManager   defaultManager ] fileExistsAtPath :filePath]) {
        
NSArray  *array = [[ NSArray   alloc initWithContentsOfFile :filePath];
        
        
IDtest . text  = [array  objectAtIndex : 0 ];
        
NameText . text  = [array  objectAtIndex : 1 ];
        
    }
    
//     注册一个通知,按下 home 键,执行 applicationWillResignActive: 方法
    
UIApplication  *app = [ UIApplication   sharedApplication ];
    [[
NSNotificationCenter   defaultCenter ] addObserver : self
                                            
selector : @selector (applicationWillResignActive:)
                                                
name : UIApplicationWillTerminateNotification
                                              
object :app];
    
}
@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值