I am creating an iOS application that reads in a text file and displays the contents in a UIText field.
For the first three consecutive runs of your application (restarting a new session without exiting), the data is considered a fine. However, in the fourth attempt, the data returned from the file are zeros.
I checked file integrity. The problem occurs when using stringWithContentsOfFile or initWithContentsOfFile.
After many hours of troubleshooting, I believe the problem is that the buffer is cleared as part of the above methods.
Any understanding of this problem is greatly appreciated. I tried a lot of things with no luck.
Here is the code that I use to read in a file:
TheString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"My_TextFile" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL];
Here is the code that I use to display the specific contents of the file (the content is placed in an array of type NSArray):
NSArray *My_Array;
My_Array= [TheString componentsSeparatedByString:@"\n"];
DisplayedData = [My_Array objectAtIndex:M[l]-1];
:
:
MyUITextView.text = DisplayedData;
NSLog(@"%@", MyUITextView.text);
On the 4th call of the code above, the returned data is empty and NSLOG returns nulls
Thanks so much for any help!
source
share