zoukankan      html  css  js  c++  java
  • UI2_NSUserDefaults

    //
    //  ViewController.m
    //  UI2_NSUserDefaults
    //
    //  Created by zhangxueming on 15/7/8.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSString *textString = [defaults objectForKey:@"key"];
        if (textString) {
            NSLog(@"textString = %@",textString);
        }
        else
        {
            NSLog(@"程序第一次启动");
        }
    
        UIButton *writeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        writeBtn.frame = CGRectMake(100, 100, self.view.frame.size.width-200, 50);
        [writeBtn setTitle:@"写入数据" forState:UIControlStateNormal];
        [writeBtn addTarget:self action:@selector(writeBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:writeBtn];
        
        UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        deleteBtn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
        [deleteBtn setTitle:@"删除数据" forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(deleteBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:deleteBtn];
    }
    
    - (void)writeBtnClicked
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"千锋教育" forKey:@"key"];
        [defaults synchronize];
    }
    
    
    - (void)deleteBtnClicked
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults removeObjectForKey:@"key"];
        [defaults synchronize];
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
  • 相关阅读:
    SQL Server XML数据解析
    c# XML和实体类之间相互转换(序列化和反序列化)
    C#解析XML详解(XPath以及带命名空间NameSpace)
    Jquery实现按钮点击遮罩加载,处理完后恢复
    jquery控制div随滚动条滚动效果
    asp.net中利用Jquery+Ajax+Json实现无刷新分页(二)
    easyUI tree点击文字展开节点
    201805牛客模拟考
    策略模式
    非线程安全演变成线程安全---原子性与加锁机制
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638879.html
Copyright © 2011-2022 走看看