parsing txt from array to UILabel
I'm actually starting to loose the will to live, this piece of code is driving me nuts!
I'm trying to get the content of mathspractice.txt into *myLabel
I'm using an array which is:
-(void)loadText
{
NSArray *wordListArray = [[NSArray alloc] initWithArray:
[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”mathspractice” ofType:@”txt”]
encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@”\n”]];
self.theMathsPractice = wordListArray;
[wordListArray release];
}
and then I'm trying to pass it into *myLabel
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
myLabel.text = *theMathsPractic开发者_如何学JAVAe;
[myScrollView addSubview:myLabel];
[myLabel release];
}
Can anyone help?
It looks on quick inspection that your theMathsPractice
is an NSArray, not an NSString, which is what you'd want to assign to the label's text property. You should at least format that array back into a string of some sort before assigning it to the label.
(Also not sure why you're dereferencing it with the *
in the assignment-- I would think that would throw a compiler error, since naked non-reference Objective-C objects are not really allowed.)
I would use the following:
myLable.text = [theMathsPractice componentsJoinedByString:@" "]);
精彩评论