0

I have 28 UIImage objects in my .h file

IBOutlet UIImageView *blackdot0, *blackdot1, *blackdot2, *blackdot3, *blackdot4, *blackdot5, *blackdot6, *blackdot7, *blackdot8, *blackdot9, *blackdot10, *blackdot11, *blackdot12, *blackdot13, *blackdot14, *blackdot15, *blackdot16, *blackdot17, *blackdot18, *blackdot19, *blackdot20, *blackdot21, *blackdot22, *blackdot23, *blackdot24, *blackdot25, *blackdot26, *blackdot27, *blackdot28;

I need to call blackdotx, where x is the number of times a button is clicked, to unhide itself in my .m file

  if (clickcount==0) {
            blackdot0.hidden = FALSE;
        }
        else if (clickcount==1){
            blackdot1.hidden = FALSE;
        }
        else if (clickcount==2){
            blackdot2.hidden = FALSE;
        }
        else if (clickcount==3){
            blackdot3.hidden = FALSE;
        }

Is there a more efficient way to accomplish this and how can I accomplish this? (Using arrays/concatenating strings with integers to call for loops?)

4

1 回答 1

0

这次这样做:

NSString* key= [NSString stringWithFormat: @"blackdot%d",clickcount];
UIImageView* imageView= [self valueForKey: key];
imageView.hidden= FALSE;

但下次我建议使用 NSArray 或 C 样式数组(最好是第一个)。

编辑

我当然知道他应该使用数组,但他问如何做到这一点。

于 2012-12-15T16:19:44.637 回答