2010-10-15 74 views
1

我使用Autoscroll示例中的Apple TapDetectingImageView類。敲擊檢測垃圾值

靜態analizer示出以下警告:

類/ TapDetectingImageView.m:68:30:{68:17-68:29}: 警告:

The left operand of '==' is a garbage value 
     if (tapCounts[0] == 1 && tapCounts[1] == 1) { 
      ~~~~~~~~~~~~^

下面所附的代碼。當變量在未被初始化的情況下讀取時發生垃圾值。但似乎tapCounts已經初始化。

如果應用程序運行正常或我應該修改任何內容,我可以忽略它嗎?

BOOL allTouchesEnded = ([touches count] == [[event touchesForView:self] count]); 

// first check for plain single/double tap, which is only possible if we haven't seen multiple touches 
if (!multipleTouches) { 
    UITouch *touch = [touches anyObject]; 
    tapLocation = [touch locationInView:self]; 

    if ([touch tapCount] == 1) { 
     [self performSelector:@selector(handleSingleTap) withObject:nil afterDelay:DOUBLE_TAP_DELAY]; 
    } else if([touch tapCount] == 2) { 
     [self handleDoubleTap]; 
    } 
} 

// check for 2-finger tap if we've seen multiple touches and haven't yet ruled out that possibility 
else if (multipleTouches && twoFingerTapIsPossible) { 

    // case 1: this is the end of both touches at once 
    if ([touches count] == 2 && allTouchesEnded) { 
     int i = 0; 
     int tapCounts[2]; CGPoint tapLocations[2]; 
     for (UITouch *touch in touches) { 
      tapCounts[i] = [touch tapCount]; 
      tapLocations[i] = [touch locationInView:self]; 
      i++; 
     } 
     if (tapCounts[0] == 1 && tapCounts[1] == 1) { // it's a two-finger tap if they're both single taps 
      tapLocation = midpointBetweenPoints(tapLocations[0], tapLocations[1]); 
      [self handleTwoFingerTap]; 
     } 
    } 

回答

0

這發生在創建變量但未初始化爲值時。在上面的代碼中你這樣做:

int tapCounts[2]; 
... 

但隨後試圖在if語句來計算它的幾行下來之前不初始化數組內容到任何東西:

if(tapCounts[0] == 1 && tapCounts[1] == 1) { 
    .... 
} 

的編譯器警告你tapCounts [0]的內容未被初始化並且是垃圾。

0

與垃圾值初始化索引0和1

請更改線路這是由於tapCounts陣列:

int tapCounts[2]; CGPoint tapLocations[2]; 

int tapCounts[2] = {0,0}; CGPoint tapLocations[2] = {0,0}; 

這將刪除初始化警告同時分析構建