標籤:des io ar os sp for 檔案 on div
#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.標題[email protected]""; //使得開始輸入的時候 標題的文本text中清空
self.文本[email protected]""; //使得開始輸入的時候 文字框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
用ios做的一個簡單的記事本