views:

25

answers:

1

Can anyone notice an error in this coding???

NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:NULL];
practiceContent = [fileContents componentsSeparatedByString:@" "]; 

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 *lblText = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
lblText.text = practiceContent;
[myScrollView addSubview:lblText];
[lblText release];

I'm trying to pass text from text.txt into a label on a scrollview...Its shows no errors when it compiles...

Thanks in advance

+1  A: 
practiceContent = [fileContents componentsSeparatedByString:@" "]; 
...
lblText.text = practiceContent;

practiceContent is an NSArray, but lblText.text requires an NSString. You should simply write

lblText.text = fileContents;

The reason the compiler doesn't complain is probably you've declared practiceContent as an id. The compiler cannot perform compile-time type check if the type is id.

KennyTM
Thanks very much Kenny you are correct that worked perfectly...TA MATE!!!
Charles Marsh