0

I'm using

for(int k=i;k<6;k++){
    int q=k+1;
    switch (q) {
        case 1:
             textbox1.hidden=YES;
            break;
        case 2:
            textbox2.hidden=YES;
            break;
        case 3:
            textbox3.hidden=YES;

            break;
        case 4:
            textbox4.hidden=YES;

            break;
        case 5:
            textbox5.hidden=YES;

            break;
        case 6:
            textbox6.hidden=YES;

            break;
        default:
            textbox1.hidden=NO;
            break;
    }
}

I was wondering if there isn't anyway to use make something like this: [@"textbox%@.hidden] = YES or something like that.. The second question I have to do something likes this:

[textbox2 setKeyboardType:UIKeyboardTypeDecimalPad];

But since Im on a for .. I can't put textbox2 I need to put "textbox%@, i" So it can detect on which textbox it is analyzing any idea?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

1

You cannot make the replacement you're asking about. It's probably possible to figure out some alternative using reflection but the resulting code will be much uglier than what you've already got. You could, however, take advantage of your q being 1-6 and use an array of text boxes:

id textboxes[] = {textbox1, textbox2, ... textbox6};


if ((q >= 1) && (q <= 6)) textboxes[q-1].hidden = YES;
else textbox1.hidden=NO;
mah
  • 39,056
  • 9
  • 76
  • 93
  • indeed good idea, works good! , and about the keyboard any ideas? – Gpadilla Apr 14 '14 at 18:29
  • It's not clear to me what you're needing to do with the keyboard type, but from what you've described it seems like you could use the same array... `int boxnum = 2; [[textboxes[boxnumn-1] setKeyboardType:...];` – mah Apr 14 '14 at 18:31
  • Haha seems like you understood what I mean haha, works perfect thanks for everything! – Gpadilla Apr 14 '14 at 18:39