1

問題があり、いくつかの方法を試しましたが、解決策が見つかりません。

問題(Objective-Cなど)0から始まる進行状況があり、反復ごとに値が3ポイント増加します。つまり、0、3、6、9、12、15など

さて、カウンターが10を超えるとアラートが表示される必要がありますが、10、20、30、40などを超える場合のみです。中間値(3、6、9など)では表示しないでください。

例えば:

0 -> nothing
3 -> nothing
6 -> nothing
9 -> nothing
12 -> ALERT!!
15 -> nothing
18 -> nothing
21 -> ALERT!!
24 -> nothing
27 -> nothing
30 -> ALERT!!
33 -> nothing
36 -> nothing
[...]

何か案が?

ありがとう!!

4

3 に答える 3

2

value10の倍数に切り捨てます。10の倍数に切り捨てます。丸めvalue-3られた値が異なる場合は、アラートを表示します。

static int roundToMultipleOf10(int n) {
    return 10 * (n / 10);
}

static void showAlertIfAppropriateForValue(int value) {
    if (roundToMultipleOf10(value) != roundToMultipleOf10(value - 3)) {
        UIAlertView *alert = [[UIAlertView alloc] init...];
        [alert show];
    }
}
于 2013-03-01T01:58:37.133 に答える
2

要件はALERT!!、x0、x1、またはx2に対してのみ表示されることを意味します。ここで、xは約10桁です。

for (int i = 0; i < 1000; i += 3) {
    if (i > 10 && i % 10 <= 2) {
        NSLog(@"ALERT!!");
    }
}
于 2013-03-01T01:58:50.113 に答える
0

すべての答えのメドレーを行った後の私の最終的な解決策。ありがとうございました!

    // Round function
    int (^roundIntegerTo10)(int) =
    ^(int value) {
        return value / 10 * 10;
    };

    // Progress evaluator
    if (_currentProgress > _nextProgress && _currentProgress >= 10) {
        NSLog(@"ALERT!!!");
        _nextProgress = roundIntegerTo10(_currentProgress) + 10;
    }
于 2013-03-01T14:40:18.113 に答える