从 for 循环中获取 img 的名称
Get name of img from for loop
我有以下代码来显示图像:
_image = [[imagesModel alloc] initFromURLWithString:imageURL completion:^(id model, JSONModelError *err) {
int x = 0;
int w = 1;
for (imageModel *img in _image.Images)
{
NSString *picString = [NSString stringWithFormat:picURL, img.filename];
NSLog(@"Images: %@", picString);
UIImage *getImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picString]]];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:getImage];
self.pictureScroll.contentSize = CGSizeMake(w * 123, 120);
imageView2.frame = CGRectMake(x * 123, 1, 120, 120);
x++;
w++;
[pictureScroll addSubview:imageView2];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[imageView2 setUserInteractionEnabled:YES];
[imageView2 addGestureRecognizer:singleTap];
clicked = img.filename;
// hide the loader view
}
[HUD hideUIBlockingIndicator];
}];
当用户点击图片时,我希望用户转到新视图,在那里他们可以看到完整尺寸的图片(现在是缩略图)。
我现在打开一个新视图,但它打开了最后的图像(Dùh)。
有谁知道如何解决这个问题,我现在脑袋一片混乱:/
一天后我自己在这里找到了答案:
tap gesture recognizer - which object was tapped?
我在int w = 0的正下方添加了
int c = 0;
在 for 循环中我添加了 2 行代码
imageView2.tag = c;
c++;
现在我根据点击的项目得到一个整数。我使用这个 int 来获取数组的文件名。
我有以下代码来显示图像:
_image = [[imagesModel alloc] initFromURLWithString:imageURL completion:^(id model, JSONModelError *err) {
int x = 0;
int w = 1;
for (imageModel *img in _image.Images)
{
NSString *picString = [NSString stringWithFormat:picURL, img.filename];
NSLog(@"Images: %@", picString);
UIImage *getImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picString]]];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:getImage];
self.pictureScroll.contentSize = CGSizeMake(w * 123, 120);
imageView2.frame = CGRectMake(x * 123, 1, 120, 120);
x++;
w++;
[pictureScroll addSubview:imageView2];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[imageView2 setUserInteractionEnabled:YES];
[imageView2 addGestureRecognizer:singleTap];
clicked = img.filename;
// hide the loader view
}
[HUD hideUIBlockingIndicator];
}];
当用户点击图片时,我希望用户转到新视图,在那里他们可以看到完整尺寸的图片(现在是缩略图)。
我现在打开一个新视图,但它打开了最后的图像(Dùh)。 有谁知道如何解决这个问题,我现在脑袋一片混乱:/
一天后我自己在这里找到了答案:
tap gesture recognizer - which object was tapped?
我在int w = 0的正下方添加了
int c = 0;
在 for 循环中我添加了 2 行代码
imageView2.tag = c;
c++;
现在我根据点击的项目得到一个整数。我使用这个 int 来获取数组的文件名。