views:

42

answers:

3

how do I set a NSString using a value from a UILabel? so far i have this but it crashes:

NSString *theScore =[[NSString alloc]initWithFormat:@"%@",scoreX.text];

scoreX is a UILabel.

can anyone help? thanks in advance

+1  A: 

Have you checked that neither scoreX nor scoreX.text is null? Otherwise this looks fine...

Nicholas M T Elliott
Thanks for the quick reply i added in scoreX.text = @"0";to the viewDidLoad, but what do I set scoreX to?
Ryan Erb
Uh, the UILabel? If you're using interface builder, declare scoreX as a IBOutlet member variable and link to it in the builder (http://www.wonderhowto.com/how-to-program-interface-builder-outlets-iboutlet-xcode-184439/) - if you're trying to declare an interface programatically, then create an instance of a UILabel.
Nicholas M T Elliott
A: 

Assuming you're using Interface Builder, it sounds like you may have bound the 'scoreX' outlet to a wrong element that doesn't have the text property.

If not, posting the text of the crash would help.

denrk
A: 

Your given code is correct. you don't try some other way.

let you try this,

NSString *theScore =[NSString stringWithFormat:@"%@",[scoreX text]];

sri