【发布时间】:2015-01-07 19:25:36
【问题描述】:
我是 iOS 开发的新手,我想在编写代码时向 UIScrollView 添加一个图像数组,然后它只显示数组的最后一个图像到 UIScrollview。我不明白是什么问题,请给我解决方案
我为此写了一个代码
for(int index=0; index < [self.imagesa count]; index++)
{
NSDictionary *dict=[self.imagesa objectAtIndex:index];
NSString *image=[dict valueForKey:@"link"];
self.zoomImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width +10.0f, self.zoomScroll.frame.size.height);
self.zoomImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
[self.zoomImage setUserInteractionEnabled:YES];
[self.zoomImage setMultipleTouchEnabled:YES];
[self.zoomImage sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"1.png"]];
[self.zoomImage setUserInteractionEnabled:TRUE];
[self.objectarray insertObject:self.zoomImage atIndex:index];
CGSize scrollViewSize=CGSizeMake(self.zoomScroll.frame.size.width*[self.objectarray count], self.zoomScroll.frame.size.height);
[self.zoomScroll setContentSize:scrollViewSize];
[self.zoomScroll addSubview:self.zoomImage];
[self.zoomScroll addSubview:[self.objectarray objectAtIndex:index]];
}
当我创建一个本地图像视图时,它显示的代码是this link shows my old code 它正在工作,但是当我为此编写代码时,它只显示最后一个数组图像,请给我解决方案。我知道这个问题问了很多次,但我没有得到解决方案。
【问题讨论】:
-
zoomImage 是你的 ScrollView?如果是,那么 index 的值是多少?
-
兄弟我编辑我的代码,这里 zoomImage 是我的 ImageView 和 ZoomScroll 是我的 Scrollview 我想将 zoomimage 添加到 ZoomScroll 中。
-
您使用“TableView”而不是使用滚动视图,并通过声明图像数组将图像添加到每个单元格。你正在以困难的方式做这件事,结果对两者来说都是一样的。
-
你在哪里分配zoomImage(uiimageView)?
-
我在我的 .h 文件中分配 zoomimage,例如 @property(retain,nonatomic)IBOutlet UIImageView *zoomImage;并且 Scrollview 也像 @property(retain,nonatomic)IBOutlet UIScrollView *zoomScroll;
标签: ios iphone uiscrollview