Ryan Erb
Ryan Erb

Reputation: 17

Get string from UILabel

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

Upvotes: 0

Views: 2918

Answers (3)

sri
sri

Reputation: 3379

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

let you try this,

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

Upvotes: 1

DPlusV
DPlusV

Reputation: 14326

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.

Upvotes: 0

Nicholas M T Elliott
Nicholas M T Elliott

Reputation: 3762

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

Upvotes: 1

Related Questions