objective-cxcodeintegerobjectname

Integer value inside name of object (xcode)


My idea is to add generated integer value to the name of UIImageView. Here is an example: I have three UIImageViews named imageView1, imageView2, imageView3. When a button is pressed I have there this simple code: self.value = value + 1; (and of course I have this "value" declared) Now I want add some code which says something like: UIImage *img = [UIImage imageNamed:@"image.png"]; [imageView(value) setImage:img]; So this I want this part of code ...[imageView(value)... to use the value I defined above. How could I do this?


Solution

  • You can set a tag for your image views:

    // set tag
    [imageView1 setTag:1];
    [imageView2 setTag:2];
    //...
    
    // get the image view with the tag
    [(UIImageView *)[self.view viewWithTag:value] setImage:img];
    //...