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
UI2_NSUserDefaults的更多相关文章
随机推荐
- 提供一个免费的CSDN下载账号
账号:windforce05password:w12345678请下载了资源后评价一下资源,以便赚回分数.
- [AnuglarJS] TweenMax with ngAnimate
Also read: http://www.cnblogs.com/Answer1215/p/3941966.html Using ngAnimate: //!annotate="YourA ...
- [AngularJS] Using Services in Angular Directives
Directives have dependencies too, and you can use dependency injection to provide services for your ...
- 总结下cocopods的安装
一:CocoaPods是什么? 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库 ...
- poj 3249 Test for Job (DAG最长路 记忆化搜索解决)
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8990 Accepted: 2004 Desc ...
- MYSQL 5.7 主从复制 -----GTID说明与限制 原创
http://www.cnblogs.com/cenalulu/p/4309009.html http://txcdb.org/2016/03/%E7%B3%BB%E7%BB%9F%E8%A1%A8- ...
- jquery动态生成css样式表
$(function(){ var a=new Date().getTime();// 实时加载,目的是清除缓存 $("head").append('<link ...
- 2. Android框架和工具之 Volley
Java基础知识强化之网络编程笔记23:Android网络通信之 Volley(Google开源网络通信库)
- vs2010 MFC Opengl实现
有的人说,学习要按部就班,学了几年的编程稍有点感悟,个人觉得面对技术的不断变化,以及需求的不断变更,如果按部就班的来搞,人生0.5的时间就浪费了,很多时候问自己,why I do need to le ...
- 源自梦想 自定义ViewGroup的整理_2
Android项目: 1.准备资源图片.图片放到hdip里和mdip里对想过的影响:对于320*480的模拟器,默认去mdip里去找图片资源,拿过来的图片可以直接用,清晰度不变.要是所要找的图片在hd ...