Is it possible to add the same view multiple times to another view. I’m trying to do this with addSubview, but the end result is the view I’ve added is only at the last position that was set.
while (count <= [_testItemArray count]) {
[self.parentView addSubview:self.childrenView];
yPosition = count * 37;
[self.childrenView setFrame:CGRectMake(0, yPosition, 0, 0)];
count++;
}
The app I am building retrieves the information that goes in the childrenView at runtime. The number of childrenView could vary each time.
You can only add an instance of a
UIViewonce, but if you subclassUIViewand create a class for your custom view, you can instantiate it as many times as you like.My suggestion is to make a class
MyCustomViewthat is a subclass ofUIView. Then your loop will look like this: