2013-03-22 46 views
0

我得到一個錯誤重新分配變量,「分配到從cincompatible類型‘ID’‘BNRItem’」,試圖於不同的對象分配給如果塊的外部聲明的變量。爲什麼我沒有得到同樣的錯誤時,我聲明的變量,當我嘗試重新分配它在if語句將值分配給它,但得到一個錯誤?謝謝你的幫助 !目標c錯誤中如果塊

BNRItem *p = [[[BNRItemStore sharedStore] getHighValueItems] <== no error 
        objectAtIndex:[indexPath row]]; 

if(indexPath.section==1){ 
     *p = [[[BNRItemStore sharedStore] getLowValueItems] <== error 
       objectAtIndex:[indexPath row]]; 

} 

回答

1

刪除*是這樣的...

​​

您已經創建了上面的指針,如果,你現在只是將值。

0

您應該使用對其操作(*)只有當你在聲明變量的第一次。

BNRItem *p = nil; 

if(indexPath.section==1){ 
     p = [[[BNRItemStore sharedStore] getLowValueItems] 
       objectAtIndex:[indexPath row]]; 
} 
+2

雖然在聲明中它不是一個解引用操作符。 – 2013-03-22 16:17:43