【问题标题】:Change two sets of datatypes daily then reset them每天更改两组数据类型,然后重置它们
【发布时间】:2012-05-10 00:25:06
【问题描述】:

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

[在图像 260combinations 中,还有其他图像组合(下面的示例),但我已经为这些制定了各种公式/编码 - 它们从第一天开始就依赖于两组 (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];
}

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

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

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

同样重要

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

【问题讨论】:

  • 您需要在问题中提供更多上下文。你在写什么样的程序?一个简单的桌面应用程序?还是司机?还是守护进程、服务器或其他一些长时间运行的进程?它是如何开始的?什么时候停止?
  • 我相信您最好保存一个日期,然后在应用加载时比较该日期。如果已经超过 13 天,请执行您需要做的事情。但是,让您每天在后台计数一次应用既浪费资源,而且如果应用被强制关闭或被看门狗杀死,甚至可能无法正常工作。
  • 我试图尽可能直接,但我可以详细说明以提供更好的想法 - 编辑
  • 今早更好编辑

标签: objective-c xcode4.2


【解决方案1】:

我已经实现了一个似乎有效的计数器/重置方法。但是我只使用了一个 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];

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 2013-10-19
    • 2019-04-26
    • 2021-08-04
    • 2023-03-18
    • 2013-08-14
    • 2016-08-18
    相关资源
    最近更新 更多