i have been looking around and haven't quite found anything on doing this and am not sure if its even possible, but this is what i am trying to achieve. please note, i am giving a very very simplified example of what i am trying do. also, and resemblance of code posted is all hypothetical and is not meant to correct code syntax. it is only meant to help further illustrate the end result desired by referencing similar type functionality. so please understand the concept before offering alternative methods...
with that said, as the title says i am trying to see if i can access an object, lets just say a uilabel via its string name or a variable without using if statements. so for example, lets say we have 3 uilabes
UILabel *label1;
UILabel *label2;
UILabel *label3;
from there we do all the appropriate synthesizing and what not. now at some point i want to reference a label based on lets say and int.
int intNumber = 2;
here is the theoretical part. i would like to now set the text of a label that has the matching int value in its name.
label(%i, intNumber).text = [NSString stringWithFormat:@"This is Label %i", intValue];
the result would then be...
label2.text = @"This is Label 2";
if the int value was 1, then label1 would be changed. or if it was 3, then label3 would be changed, etc...
or if the same process could be done using the string name of the label.
int intValue = 1;
NSString *labelName;
then at some point
labelName = [NSString stringWithFormat:@"label%i",intValue];
now somehow set the text of label1 by referencing "labelName" to call it. if anyone could offer a suggestion or comment to wether something like this can even be done it would be greatly appreciated. i know you can reference classes and selectors by string name, but i'm not sure about objects? i don't know if "valueForKey:" is the way i should be looking to do this?
sorry for the long winded post, but i just wanted to make sure i stated what i wanted to do.
See Question&Answers more detail:
os