views:

124

answers:

2

Hello All,

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?

+1  A: 

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

quixoto
Thanks Ben, I understand what I was missing now... I'll post back! Thanks again
Charles Marsh
A: 

I would use the following:

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