每天更改两组数据类型,然后重置它们



我需要每天为 iOS 应用程序更改两组图像数据和两组文本数据。第一个图像集是x1-13.png,第二个是y1-20.png。在重复循环之前,总共有 260 种组合(13x20 天(。有 2x260 组文本数据(文本 A、文本 B(并行运行。它们必须与特定的公历日期相对应,并在组合中循环。该应用程序将打开,查看日期并加载相应的数据。它还需要跳过闰年日(2/29(。

[在图像 260 组合中,还有其他图像组合(下面的示例(,但我已经为这些制定了各种公式/编码 - 它们从第一天开始依赖于两个集合(x1.png,y1.png(并将致力于实现。

目前,我所能做的就是手动更改两组整数作为计数器以显示不同的图像。例如:

int x = 2;
int y = 2;
-(void)getImage{
if (y) {
UIImage *theYimg = [UIImage  imageNamed:[NSString stringWithFormat:@"SetY%i.png", y]];
    [MainImageView setImage:theYimg];
int additionalImagery;
if ((x == 2 ||x == 7||x==12) && y <9) {
        additionalImagery = y + 12;
        UIImage *addimg = [UIImage  imageNamed:[NSString stringWithFormat:@"SetY%i.png", additionalImagery]];
        [secondImageView setImage:addimg];
        UIImage *thirdimg = [UIImage  imageNamed:[NSString stringWithFormat:@"SetX%i.png", x]];
        [thirdImageView setImage:thirdimg];
}

是否有一个循环可以每天计数 (++(,直到它们到达图像集的末尾,然后再次从第一个图像重置自己? - 相当于 :

int x = 1; x <=13; x++; //then reset to x=1 again after 13days
int y = 1; y <=20; y++; //then reset to y=1 again after 20days

周期将在同一天开始,但显然它们需要在不同的日子重置。

同样重要的是

如何在每日计划中实施它们?

我已经实现了一个似乎有效的计数器/重置方法。但是,我只使用了NSTimer间隔来检查这一点:

-(void)countUpAndReset{
x++;
if (x <= 13) {
    [self getImage];
}
else if (x > 13){
    x = 1;
    [self getImage];
}
y++;
if (y <=20) {
    [self getImage];
}
else if (y >20){
    y = 1;
    [self getImage];
}
}

并在 ViewDidLoad 中:

- (void)viewDidLoad
{
[super viewDidLoad];
x = 1;
y = 1;
[self getImage];
theTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(countUpAndReset) userInfo:nil repeats:YES];

现在我必须将其映射到从日期开始的公历上,例如 12/25/2010 到 (++( 每天(减去闰年日 2/29(..?

相关内容

最新更新