为什么我的整数没有添加负值?

时间:2015-03-10 16:23:35

标签: objective-c loops nsinteger

这里真的很困惑。

NSInteger iteration;
NSInteger direction;

- (void)pulse {
    self.position = ccpAdd(self.position, vectors[iteration]);
    iteration = iteration + direction;
    if (iteration >= totalIterations) {
        direction = -1;
        iteration = totalIterations - 1;
    } else if (iteration < 0) {
        direction = 1;
        iteration = 0;
    }
}

一旦迭代超过totalIterations,迭代永远不会回到下面。当循环再次出现时,po迭代显示它等于totalIterations。

AFAIK我不会在其他地方添加它。

我错过了什么吗?与NSInteger有关吗?

1 个答案:

答案 0 :(得分:0)

子类具有与父类相同的实例变量名。父类正在递增此实例变量。