I got 30 of these codes, with the same implementation:
// .h
@interface ViewController : UIViewController{
IBOutlet UIImageView *circle;
IBOutlet UIImageView *circle2;
}
@property (nonatomic, retain) IBOutlet UIImageView *circle;
@property (nonatomic, retain) IBOutlet UIImageView *circle2;
// .m
@implementation ViewController
@synthesize circle;
@synthesize circle2;
- (void)viewDidLoad
{
circle = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"Circle.png"]];
circle2 = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"Circle.png"]];
}
And somewhere in my code, Im adding it as a subview.
My problem is,Is there a way to make it shorter, for it to be maintainable.
You can use one
IBOutletCollectioninstead of 30IBOutlets. You probably want to set the tag on eachUIImageViewthough, so you can still tell them apart.(This answer assumes you use a nib. Remove the lines where you instantiate the
UIImageViews inviewDidLoadif so.)