用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

 
 
 

转载于:https://www.cnblogs.com/daijiahong/p/4131076.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值