简体   繁体   中英

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

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

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

let you try this,

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM