I created a view with a Nib.
I want to add multiple instances of this subview but only the last one I add is displayed.
NSArray * nibArray = [[NSBundle mainBundle] loadNibNamed:@"SBFiveBarCountView"
owner:self
options:nil];
SBFiveBarCountView * fiveBarCount1 = (SBFiveBarCountView *)[nibArray objectAtIndex:0];
fiveBarCount1.frame = CGRectMake(22, 15, 16, 57);
SBFiveBarCountView * fiveBarCount2 = (SBFiveBarCountView *)[nibArray objectAtIndex:0];
fiveBarCount2.frame = CGRectMake(45, 15, 16, 57);
[self.view addSubview:fiveBarCount1];
[self.view addSubview:fiveBarCount2];
After I do that, only fiveBarCount2 is actually added to the view
What am I doing wrong?
Thanks
You are assigning the same object to two different variables. That is, it’s the object at location zero of the array no matter what you name it.
Since
loadNibNamed:is the method that creates a new instance of the object (inside the array), you would need to call it a second time to get a differentSBFiveBarCountViewobject.