2012-05-11 101 views
0

好,所以我的程序似乎運行良好,並做我需要的所有計算,程序需要的最後一塊是增量切割清單。所以我試圖建立一個NSMutable數組,並使用以前設置的變量,我最終將填充一個表。只有當我運行代碼並點擊計算按鈕,程序凍結,並沒有任何顯示在NSLOG等 我可以不使用以前的變量設置以外的for循環?或發生了什麼?卡住for循環我想,不能使用循環外設置的變量?

-(IBAction)calculateGo 
{ 
    BuildNavAppDelegate *buildNavDelegate = (BuildNavAppDelegate *)[[UIApplication sharedApplication] delegate]; 

    float iridge = ([ridge.text intValue]); 
    float ihip = ([hip.text intValue]); 
    float ispacing = ([rafterSpace.text intValue]); 

    float floatTLPMR = [buildNavDelegate.TLPMR floatValue]; 
    int floatRafter = [buildNavDelegate.raftThicknessPassed intValue]; 
    int comraftbird = [buildNavDelegate.comRaftBirdPassed intValue]; 

    float mitre = (45 * M_PI)/180; 
    float y = tanf(mitre); 
    float mitreThickness = sqrt((y*y)+1) * ihip; 

    float TLRafterSpace = (floatTLPMR * ispacing); 

    float firstCreeper = (TLRafterSpace + (mitreThickness/2))-(floatRafter/2); 
    firstCreep.text = [[NSString alloc] initWithFormat:@"%.1f", firstCreeper]; 

    float comSetBack = floatTLPMR * (iridge/2); 
    comRaftSetBack.text = [[NSString alloc] initWithFormat:@"%.1f", comSetBack]; 

    float crownSetBack = (floatTLPMR * (floatRafter/2)); 
    crownEndSetBack.text = [[NSString alloc] initWithFormat:@"%.1f", crownSetBack]; 

    creeperArray = [[NSMutableArray alloc] initWithCapacity:20]; 

for (int x = firstCreeper; x <= comraftbird; x + TLRafterSpace) { 
[creeperArray addObject:[NSString stringWithFormat:@"%d", x]]; 
} 
} 

回答

1

你是停留在一個無限循環,因爲你忘了增加的x值:

for (int x = firstCreeper; x <= comraftbird; x + TLRafterSpace) 
              ^^^^^^^^^^^^^^^^^ 

這也許應該是:

for (int x = firstCreeper; x <= comraftbird; x += TLRafterSpace) 
+0

那麼容易。我已經錯過了一遍又一遍,謝謝! –