2014-06-17 52 views
-1
const UIView * vLocalBottomButton = self.BottomButton; 

    vLocalBottomButton =nil; 

基本上我想將self.BottomButton傳遞給一個將在主線程外部運行的方法。當使用視圖時,它將在主線程中完成。這段代碼如何編譯?

我只需要確保視圖不會改變。就這樣。所以我把它放到一個局部變量,然後傳遞該局部變量,以確保vLocalBottomButton沒有改變。

回答

3

您應該創建常量指針。在你的情況下:

UIView * const vLocalBottomButton = self.BottomButton; 

//this won't compile therefore 

vLocalBottomButton =nil; 
+0

爲什麼指針不是const?你如何解釋這個語法規則? –

+0

瞭解C中常量值和常量指針之間的區別http://stackoverflow.com/questions/10091825/constant-pointer-vs-pointer-on-a-constant-value –