Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

learningCentres

macrumors newbie
Original poster
Feb 25, 2010
1
0
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.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.