How to add subviews from an array in uiview?

I have my subviews stored in an array ... what I want is to place these subzones in my main view from the array ....

for(int i=0;i<[imageViewArray count];i++)
    {
        NSLog(@" image array count is %d",[imageViewArray count]);
       // countlayers= countlayers+1;
      //  [canvasView insertSubview:[imageViewArray objectAtIndex:i] atIndex:countlayers];
        [canvasView addSubview:[imageViewArray objectAtIndex:i]];
    }

Can you tell me what I'm doing wrong

+3
source share
2 answers

If it imageViewArrayreally contains initialized views, and if these views already have the correct attributes frame, you are not doing anything wrong (even if your code may be more elegant).

Also, of course, we need to make sure that the canvasView is really initialized and visible on the screen. Try setting backgroundColor to something noticeable:

canvasView.backgroundColor = [UIColor greenColor];

, , canvasView, , , , , .

for (UIView *imageView in imageViewArray) //this is fast enumeration. You can get it through code completion by typing forin
{
    NSLog(@"%@", imageView); //let take a look at the imageView. What is its frame?
    [canvasView addSubview:imageView];
}
0

. imageViewArray , , .

for (UIImageView *imageView in imageViewArray) //enumeration. 
{
    //let set frame for image view before adding to canvasView
    [imageView setFrame:CGRectMake(x,y,w,h)]; 
    //Also make sure imageView has image or not
    if(imageView.image)
    [canvasView addSubview:imageView];
}
0

All Articles