3

我将我的子视图存储在一个数组中......我想要将这些子视图从数组中放置到我的主视图中......

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]];
    }

你能告诉我我做错了什么吗

4

2 回答 2

0

如果 imageViewArray确实包含已初始化的视图,并且如果这些视图已经具有正确的frame属性,那么您没有做错任何事情(即使您的代码可能更优雅)。

此外,当然,我们必须确保 canvasView 确实已初始化并且在屏幕上可见。尝试将其 backgroundColor 设置为明显的:

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's take a look at the imageView. What is its frame?
    [canvasView addSubview:imageView];
}
于 2012-05-05T12:16:04.527 回答
0

使用枚举使用 imageViewArray 在画布视图上添加图像,并且可能您也缺少图像的设置框架。

for (UIImageView *imageView in imageViewArray) //enumeration. 
{
    //let's 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];
}
于 2012-05-05T12:24:18.890 回答