【问题标题】:Get name of img from for loop从 for 循环中获取 img 的名称
【发布时间】:2015-06-10 07:23:52
【问题描述】:

我有以下代码来显示图像:

_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)。 有谁知道如何解决这个问题,我的大脑现在一团糟:/

【问题讨论】:

  • 请注意,除非 IDE 本身有问题,否则不应使用 xcode 标签。

标签: objective-c cocoa-touch uiimage


【解决方案1】:

一天后我自己在这里找到了答案:

tap gesture recognizer - which object was tapped?

我在 int w = 0 的正下方添加

int c = 0; 

在 for 循环中我添加了 2 行代码

imageView2.tag = c;
c++; 

现在我根据点击的项目得到一个 int。我使用这个 int 来获取数组的文件名。

【讨论】:

    猜你喜欢
    • 2015-06-13
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多