【问题标题】:Going to next image and previous image转到下一个图像和上一个图像
【发布时间】:2011-05-09 13:30:35
【问题描述】:

我有这个代码:

- (IBAction)next {
          // <-- here
        index++;
        // Set imageCount to as many images as are available
        int imageCount=3;
        if (index<=imageCount) {
            NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index];
            [picture setImage: [UIImage imageNamed: imageName]];
        }
    }
    - (IBAction)prev {
          // <-- here
        index--;
        // Set imageCount to as many images as are available
        int imageCount=3;
        if (index > 1) {
            NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index];
            [picture setImage: [UIImage imageNamed: imageName]];
        }
    }

第一个链接到一个按钮,可以正常工作并向前更改图像。第二个链接到另一个按钮,但只会后退一个图像。我真的被困住了,我需要严重的帮助。请有人帮助我。 (索引是一个属性和合成) ImageCount 不是。也没有图像列表。 图像是: img1.jpg img2.jpg img3.jpg

谢谢。

【问题讨论】:

    标签: iphone objective-c xcode image


    【解决方案1】:

    如果您的图片名称是从 1 开始的(只有 img1.jpg、img2.jpg 和 img3.jpg),也许您的 -prev 操作应该检查 if (index &gt;= 1)

    但是,如果您只拥有相同的三张图片,那么执行此操作的方法要简单得多。也许你应该解释你的总体目标(从一个非常高的层次——你希望你的应用做什么),社区可以帮助你选择更好的路径。

    【讨论】:

      猜你喜欢
      • 2016-07-14
      • 2013-12-12
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 2016-12-21
      • 2013-12-21
      相关资源
      最近更新 更多