在UITextview中加载巨大的文本文件崩溃 [英] Loading huge Text file in UITextview crashes

查看:109
本文介绍了在UITextview中加载巨大的文本文件崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在UITextView中更新一个巨大的文本文件。但该设备有时会挂起或崩溃。文本文件大小为4MB。

I want to update a huge text file in UITextView. But the device just hangs or crashes some times. The text file size is 4MB.

UITextView已从Interface Builder添加。

The UITextView is been added from Interface Builder.

我正在从文档目录加载文件。
下面是加载文本文件的代码: -

I am loading the file from document directory. Below is the code for loading the text file:-

NSError *err = nil;
txtView.text =[NSString stringWithContentsOfFile:documentPath encoding:NSUTF8StringEncoding error:&err];






因为我想编辑文件我无法加载它在WebView中更快,并且工作正常。


As I want to edit the file I cannot load it in WebView which is much faster and it works properly.

有什么方法我只能部分加载文本文件(一次一页)所以它没有加载或以其他方式正确加载整个文件需要花费很多时间吗?

Is there any way were I can only partially load the text File(one page at a time) so it doesn't take much time to load or some other way to load the whole file properly ?

任何正确方向的提示都将受到高度赞赏。

Any hint in right direction would be highly appreciated. .

推荐答案

听起来像是一个令人讨厌的问题,因为你必须要测量文本中的确切数量一页。您可以尝试使用UIScrollView属性和委托textview的方法(如contentOffset),但我不推荐它。

Sounds like a nasty problem, because you would have to measure how much text has to fit exactly in one page. You could try and play around with the UIScrollView-properties and delegate methods of the textview (like contentOffset), but I would not recommend it.

就个人而言,我会尝试将文本内容划分为多个页面(多个NSStrings),然后使用两个按钮next,previous在文本视图中的页面之间切换。

Personally, I would try to divide the text content into multiple pages (multiple NSStrings) and then use two buttons "next", "previous" to switch between pages within the text view.

这篇关于在UITextview中加载巨大的文本文件崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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