Iphone 如何将子视图从阵列添加到uiview?
我将我的子视图存储在一个数组中…我想要的是将这些子视图从数组中放置到我的主视图中Iphone 如何将子视图从阵列添加到uiview?,iphone,xcode,Iphone,Xcode,我将我的子视图存储在一个数组中…我想要的是将这些子视图从数组中放置到我的主视图中 for(int i=0;i<[imageViewArray count];i++) { NSLog(@" image array count is %d",[imageViewArray count]); // countlayers= countlayers+1; // [canvasView insertSubview:[imageViewArray o
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]];
}
for(int i=0;i如果imageViewArray
确实包含初始化视图,并且这些视图已经具有正确的frame
属性,那么您没有做错什么(即使您的代码可能更优雅)
当然,我们还必须确保canvasView确实已初始化并在屏幕上可见。请尝试将其背景色设置为明显的颜色:
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];
}
使用枚举在画布视图上使用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];
}
首先,我建议使用快速枚举什么是canvasView?如果你想添加图像,那么你可以在主视图上显示图像的位置上有ImageView/请解释你的问题?canvasView是UIimageView还是Uiview?canvasView是Uiview还是像self一样。view n在我的数组中已经有imag了eviews中有图像。所以任何解决方案。n关于快速枚举,你能举个例子吗..我还没有使用过..thnximageviewArray是一个数组,其中有初始化的UIView要添加到我的主视图或self.view中。然后试着运行我的代码。它不会比你的更好,但日志输出可以帮助我们找出原因G