用ios做的一个简单的记事本

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *标题;  //用的是一个text按键

@property (weak, nonatomic) IBOutlet UITextView *文本;  //用的是一个text view按键


@end

@implementation ViewController
- (IBAction)创建:(id)sender {     //创建的是一个button按键 点击就可以进行书写了
    self.标题.text=@"";    //使得开始输入的时候 标题的文本text中清空
    self.文本.text=@"";    //使得开始输入的时候  文本框text view清空
}
- (IBAction)保存:(id)sender {   //创建的一个button按键 用以保存已经写的文本
    NSString *name=self.标题.text;  //将标题中的输入文本赋值给name这样的一个指针
    NSString *content=self.文本.text;  //将文本中的输入内容赋值给content这样的一个指针
    NSString *path=[NSString stringWithFormat:@"/Users/apple/Desktop/%@",name];  //将你要保存的“地址”给一个path的指针变量
    [content writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];//将content中的文本内容保存在path我那本中.如果不存在则自行建立
}
- (IBAction)读取:(id)sender {
    NSString *name=self.标题.text;  //将标题中的输入文本赋值给name这样的一个指针
    NSString *path=[NSString stringWithFormat:@"/Users/apple/Desktop/%@",name];//将你要保存的“地址”给一个path的指针变量
    NSString *content=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];//把地址中的文件取出来给content
    self.文本.text=content;//将content中的文本显示在text view的文本框中
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)标题:(id)sender {
}
@end

 
 
 
posted @ 2014-11-29 16:06  代佳宏  阅读(513)  评论(0编辑  收藏  举报