Charles Marsh
Charles Marsh

Reputation: 465

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 = *theMathsPractice;
        [myScrollView addSubview:myLabel];
        [myLabel release];
        }

Can anyone help?

Upvotes: 0

Views: 503

Answers (2)

ennuikiller
ennuikiller

Reputation: 46965

I would use the following:

myLable.text = [theMathsPractice componentsJoinedByString:@" "]);

Upvotes: 0

Ben Zotto
Ben Zotto

Reputation: 71008

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.)

Upvotes: 1

Related Questions