序列化与反序列化(NSDictionary),监听键盘

@interface ViewController ()

#define FileName @"Student.plist"

#define KName @"KName"
#define KBirth @"KBirth"
#define KSex @"KSex"
#define KNumber @"KNumber"
#define KHome @"KHome"

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
    
    NSDictionary *dictionary=[NSDictionary dictionaryWithContentsOfFile:[self filePath]];
    if (dictionary) {
        self.nameField.text=[dictionary objectForKey:KName];
    }
}
     


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)save:(id)sender {
    
    do {
        NSString *name=[self.nameField text];
        NSString *bith=[self.birthField text];
        NSInteger sex=[self.sexSeg selectedSegmentIndex];
        NSString *home=[self.homeField text];
        NSString *number=[self.numberField text];
        if (!name||!bith||!home||!number) {
            break;
        }
        
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        [dic setObject:name forKey:KName];
        [dic setObject:bith forKey:KBirth];
        [dic setObject:[NSNumber numberWithInteger:sex] forKey:KSex];
        [dic setObject:number forKey:KNumber];
        [dic setObject:home forKey:KHome];
        
        if ([dic writeToFile:[self filePath] atomically:YES]) {
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"保存成功!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }
        return;
        
    } while (0);

    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"警告" message:@"基本信息不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertView show];
}

//返回沙盒路径
- (NSString *)filePath
{
    NSArray *array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=  [[array objectAtIndex:0] stringByAppendingPathComponent:FileName];
    return path;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nameField resignFirstResponder];
    [self.birthField resignFirstResponder];
    [self.numberField resignFirstResponder];
    [self.homeField resignFirstResponder];
}
- (void)KeyboardWillShow
{
    [UIView beginAnimations:@"show" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    CGRect rect=self.view.frame;
    rect.origin.y=-40;
    self.view.frame=rect;
    [UIView commitAnimations];
}
- (void)KeyboardWillHide
{
    [UIView beginAnimations:@"hide" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    CGRect rect=self.view.frame;
    rect.origin.y=0;
    self.view.frame=rect;
    [UIView commitAnimations];
}
View Code

 

转载于:https://www.cnblogs.com/iOS-Code/p/4716695.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Chrome翻译插件是一款非常实用的工具,可以帮助用户利用谷歌翻译功能将网页内容翻译成自己熟悉的语言。而CSDN作为中国最大的 IT 社区,拥有着丰富的技术资源和文章,因此,很多人都希望能够使用Chrome翻译插件来辅助阅读和理解CSDN上的技术文章。 要下载Chrome翻译插件,首先需要打开Chrome浏览器,并进入Chrome网上应用店。在搜索栏中输入“翻译插件”,就可以看到与翻译相关的插件。选择安装量较大、评分较高的插件,如“谷歌翻译”或“划词翻译”等,然后点击“添加至Chrome”进行安装。 安装完成后,在浏览器的工具栏上就可以看到插件的图标。当用户浏览CSDN网站并遇到需要翻译的内容时,只需要单击插件图标,即可将整个网页翻译成自己想要的语言。同时,也可以通过选择文本或鼠标悬停在单词上来进行局部翻译,方便用户查阅。 总之,通过下载Chrome翻译插件,用户可以轻松将CSDN网站的技术内容翻译成自己熟悉的语言,更好地学习和应用相关的技术知识。 ### 回答2: Chrome翻译插件是一种方便的工具,可以在浏览器中直接翻译网页的内容CSDN作为一个技术社区网站,有很多技术资料是用英文编写的,因此非常适合使用翻译插件浏览。 要下载chrome翻译插件,可以在Chrome网上应用商店中搜索:“翻译插件”,然后选择自己喜欢的插件,点击“下载”即可。其中,常用的翻译插件包括“谷歌翻译”、“百度翻译”、“有道翻译”等。 对于CSDN网站,推荐使用“谷歌翻译”插件。下载完插件后,浏览CSDN网站时,只需要点击插件图标,选择翻译语言,即可将网页内容快速翻译成自己的语言。同时,该插件也支持划词翻译和语音翻译等功能,非常实用。 总之,Chrome翻译插件是一个非常有用的工具,为浏览非母语网站的人们提供了便利。对于想要浏览CSDN网站的技术爱好者,下载一个翻译插件,可以更好的理解和学习各种技术资料。 ### 回答3: 要下载chrome翻译插件,首先需打开chrome浏览器,然后在地址栏中键入Chrome网上应用商店的网址:(https://chrome.google.com/webstore/category/extensions), 在搜索框中输入"翻译插件",会得出很多翻译插件供选择,其中包括“谷歌翻译”等热门插件。 如果您要下载“谷歌翻译”插件,只需点击其图标,进入应用页面,再点击“添加至Chrome”即可。随着下载的完成,在右上角便可看到插件图标。当您需要翻译时,只需点击插件的图标,选择“选文翻译”,文本就会瞬间被翻译成您设置的目标语言。如果您想获取更多设置项,只需右击icon,选择“选项”即可。 总之,下载Chrome翻译插件简单快捷,让您可以高效获取丰富的语言翻译服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值