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.
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];
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.
.
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.
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.