I have came across a very interesting problem. I have a UILabel and a number of the label properties. Corresponding to each property, there is a value that is to be set for the label. This property-value thing is in a dictionary (as key-value pair). Lets say, there is a key-value pair as “text”:”abc” (here text is my key and abc is the corresponding text that has to be set). I dont want to use myLabel.text = ; just like the value here can come from any array or nsstring, I want the property also to be dynamic. Here is a sample of what I want:
NSMutableDictionary *tryDict = [[NSMutableDictionary alloc]init];
[tryDict setObject:@"abc" forKey:@"text"];
UILabel *lblName = [[UILabel alloc]init];
NSArray *allKeys = [tryDict allKeys];
NSArray *allValues = [tryDict allValues];
NSSTring *textProp = [allKeys objectAtIndex:0];
lblName.textProp = [allValues objectAtIndex:0]; // giving an error since textProp is not a UIlabel property.
Is there any way to achieve this??
[lblName setValuesForKeysWithDictionary:tryDict]this method is just what you need.