Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
Um, I haven't been able to figure out how to use variables to name variables.

For example the piece below here, would be so much cleaner inside a for loop.

I want to transform this piece:
Code:
cell.textLabel0.text = [localValues objectAtIndex:0];
cell.textLabel1.text = [localValues objectAtIndex:1];
cell.textLabel2.text = [localValues objectAtIndex:2];
cell.textLabel3.text = [localValues objectAtIndex:3];
cell.textLabel4.text = [localValues objectAtIndex:4];
cell.textLabel5.text = [localValues objectAtIndex:5];

into
Code:
for (int i = 0; i < 6; i+=){
   cell.textLabel+i<?HowDoIIncrement?>.text = [localValues objectAtIndex:i];
}
 

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
So, you have a single table cell with six labels in it, is that correct?

In this case yes.

Phoney, can you give me a bit more than valueForKey - you don't mean a Dictionary?

I don't need to stick the variables in a dictionary or anything, I just want to be able to do like the example. No biggie really, just one of those things in Java that are really handy.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The usual reason to use it is to get around Apple's private apis to get/set private ivars ;-) which is illegal of course and you should never do it.

Actually I don't think I've ever used it in a shipping app. It's a little too weird for me.

The kind of thing OP wants to do can be done this way but it's a little too weird for me.
 

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
Ok, I see where you are going with valueForKey. It will actually do the job.

To be honest though the code is a fair bit convoluted so I'm probably better off not looping through. It's just one of those things I suppose, quirks of different languages.

Thanks for entertaining me anyway!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.