Eric
Eric

Reputation: 157

Reference a UILabel name as a variable

If I have a UILabel:

USD_time.text = [NSString stringWithFormat:@"%@ %.2dm %.2ds", pre, min, sec];

Is it possible to reference the UILabel as a variable?

Ex:

NSString *myLabel = @"USD_time";
myLabel.text =  [NSString stringWithFormat:@"%@ %.2dm %.2ds", pre, min, sec];

I know this does not work, I am unsure what the proper format would be. Also I am unsure what this is called.

Thank so much.

Upvotes: 2

Views: 517

Answers (2)

Bartosz Ciechanowski
Bartosz Ciechanowski

Reputation: 10333

Read up on Key Value Coding, it's just the thing you are looking for.

Upvotes: 3

Abdullah Md. Zubair
Abdullah Md. Zubair

Reputation: 3324

Think it simple. Take an object UILabel *myLabel, then take a NSString object NSString *myLabelText. Then put myLabelText=[NSString stringWithFormat:@"%@ %.2dm %.2ds", pre, min, sec]; After that set this text to your label like myLabel.Text=myLabelText

Upvotes: 2

Related Questions