views:

229

answers:

1

I have this code

NSArray *wordListArray = [[NSArray alloc] initWithArray:
[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”sowpods” ofType:@”txt”]
encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@”\n”]];

My question is how can I extract this text and update a label in a Scrollview? I just need the user to be able to scroll down and read whats in the text file...

A: 

Sounds like what you want to do is something like:

CGRect appFrame = [[[UIApplication sharedApplication] keyWindow]frame];
UIScrollView* scrollView = [[[UIScrollView alloc] initWithFrame:appFrame] autorelease];
CGRect lblFrame = CGRectMake(0.0f, 0.0f, scrollView.frame.size.width, 20.0f);
for (NSString* word in wordListArray)
{
  UILabel* lbl = [[[UILabel alloc] initWithFrame:lblFrame]autorelease];
  lbl.text = word;
  [scrollView addSubview:lbl];
  lblFrame.origin.y += 20.0f;
}
scrollView.contentSize = CGSizeMake(lblFrame.size.width, lblFrame.origin.y);
[mainView addSubview:scrollView];  // mainView = up to you

(NB: I haven't tested this, could contain errors, but just want to give you ideas to work with.)

Felixyz