How can I get text from my .txt file into my UIScrollView?
At the moment I have this which does not work, it compiles just fine but will not show any text.
Thanks so much in advance
At the moment I have this which does not work, it compiles just fine but will not show any text.
Code:
-(void)loadText
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *textFilePath = [bundle pathForResource:@"mathsquestions" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath];
NSArray *mathsText = [[NSArray alloc] initWithArray:[fileContents componentsSeparatedByString:@" "]];
self.mathsPracticeTextArray = mathsText;
[mathsText release];
}
Code:
- (void)viewDidLoad {
[super viewDidLoad];
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(320, 960);
myScrollView.pagingEnabled = FALSE;
myScrollView.scrollEnabled = TRUE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
myLabel.text = [mathsPracticeTextArray componentsJoinedByString:@" "];
[myScrollView addSubview:myLabel];
[myLabel release];
}
Thanks so much in advance