如何在 iphone 的 Uitextview 中保存文本 [英] How to save text in Uitextview for iphone

查看:25
本文介绍了如何在 iphone 的 Uitextview 中保存文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

笔记作为导航基础应用程序中的UITextView.如何在笔记中写入后保存文本数据.如何识别键盘返回.需要设置任何键返回Notes.我需要存储设备.当用户在笔记中输入文本时,第二次后也可以看到上一页,如果可能的话,写到上一页的行尾开始追加.请发布一些教程链接,因为我对这个主题不太了解,我需要了解概念.

Notes as a UITextView in navigation base application .How to save text data after writing in notes .How to identify return from keyboard. need to set any key for return Notes.I need to store device. When user enter the text in notes , after second time able to see previous page also, if its possible write to previous page end of line to start that is appended. plz post some tutorial link , because i am not much about this topic, i need ti understand concept .

推荐答案

创建在单击按钮时调用的函数,测试用户是否按下了 Enter 键,或测试用户是否已从 UITextView 中移除焦点:

Create function that is called on a button click, test if the user has hit enter, or test if the user has removed focus from the UITextView:

-(IBAction)saveText
{

获取您要创建的文件的路径:

Get the path to the file you want to create:

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"savedText.txt"];

从 UITextView 获取文本(用你的 UITextView 的名称替换 textView):

Get the text from the UITextView (replace textView with the name of your UITextView):

NSString *savedString = textView.text;

将字符串写入文件:

    [savedString writeToFile:documentTXTPath atomically:YES];
}

这篇关于如何在 iphone 的 Uitextview 中保存文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆