zanona
zanona

Reputation: 12717

Re-using IBOutlet programmatically

I have an UIView created in IB with some labels and custom colours and linked that as an IBOutlet so I could have access to it in my viewController.

@property (strong, nonatomic) IBOutlet UIView *tile;

although I would like to create more of this outlet within a loop:

- (void)viewDidLoad {
    [super viewDidLoad];
    int i = 0;
    while (i <= 9) {
        UIView *cTile = [self.tile copy];
        [self.view addSubview:cTile];
        i += 1;
    }
}

So I'm trying to copy this tile outlet and then add the copied view to the main view. Apparently this can't be done and returns an error.

Is it possible to achieve such behaviour and re-use/duplicate an IBOutlet?

Upvotes: 0

Views: 689

Answers (1)

Martin
Martin

Reputation: 747

I dont think what you want to do is possible as UIView doesn't conform to the NSCopying protocol.

Best bet would be to create your "tile" as a UIView subclass or crate a nib for it and then you can reload it as many times as you want.

Upvotes: 2

Related Questions