2012-01-04 68 views
0

這裏是我的代碼:如何枚舉CGPoints的nsmutablearray?

for (NSValue * i in cgpointarray){ 
     [text setHidden:NO]; 
     CGPoint temppoint = i.CGPointValue; 
     if (touchended.x < temppoint.x+36 && touchended.x > temppoint.x-36 && touchended.y < temppoint.y+36 && touchended.y > temppoint.y -36){ 
      spacetouched = i; 
      break; 
     } 

目的是搜索每個空間(陣列的cgpoint X)+或 - 36個像素的touchended CGPoint。不過,我創建了一個名爲text的標籤並將其設置爲隱藏,當此代碼運行時,文本標籤不顯示,因此我認爲它沒有執行代碼。 cgpointarray是一個NSMutableArray,如果這有什麼區別的話。

編輯:在這條線:CGPoint temppoint = i.CGPointValue;編譯器說:「我」隱藏的實例變量

+0

您是否嘗試過在循環中設置斷點或日誌語句以確定該循環是否僅執行或者其他錯誤?因爲你描述的內容有很多可能的原因。 – Chuck 2012-01-04 19:16:22

+0

在循環內部放置一個日誌語句'NSLog(@「text is%@」,text)',然後你就會知道這個循環是否運行,次數是多少,如果'text'是零。此外,'[我CGPointValue]'可能是這裏的首選語法(意見) – 2012-01-04 19:19:50

+0

@FirozeLafeer我把一個NSLog放入循環中,當它在循環之前我沒有任何反應。也改爲'[i CGPointValue]' – Puregame 2012-01-04 19:30:44

回答

1

你爲什麼不解決警告本地聲明 - 好像你有一個實例變量也叫我?

+0

我不知道如何。或它的意思。 – Puregame 2012-01-04 19:31:08