2011-11-15 59 views
0

這個SHOULD是簡單的。相反,在最後一個小時左右,我感到困惑。無論我做什麼,這個變量拒絕改變值


頭文件:

CellBackgroundView距離的UIView衍生的自定義類。

@interface CustomCell : UITableViewCell { 

    CellBackgroundView *customBackgroundView; 

} 

@property (strong) CellBackgroundView *customBackgroundView; 
預期不起作用


代碼:

所有我想要做的就是分配東西customBackgroundView。

customBackgroundView = [[CellBackgroundView alloc] initWithFrame:CGRectZero]; 
    [self addSubview:customBackgroundView]; 

-

什麼也沒有發生。在調試器中,我可以看到customBackgroundView是0x0。以下也不起作用,雖然「背景」確實分配了一個內存位置。 customBackgroundView仍然是0x0。

CellBackgroundView *background = [[CellBackgroundView alloc] initWithFrame:CGRectZero]; 
    customBackgroundView = background. 
    [self addSubview:customBackgroundView]; 


發生了什麼事?爲什麼這不起作用? 我打開了ARC。


EDITS:

CellBackgroundView的基礎是:

- (BOOL) isOpaque { 
    return NO; 
} 

-(void)drawRect:(CGRect)aRect { 
    //Custom drawing code 
} 

而且,上面的代碼,當我用的UITableViewCell的官方 'backgroundView' 屬性的罰款。

+0

任何東西CellBackgroundView執行有關?像一個自定義的initWithFrame? – djromero

+0

你可以發佈'CellBackgroundView'的'initWithFrame:'方法嗎?它可能是通過它CGRectZero返回零。 – jbat100

+0

@madmw我已經發布了該類的基礎 - 請參閱底部的編輯。 –

回答

1

最後....答案確實是Xcode壞了。

或者說,調試器是。無論我設置該變量,Xcode都拒絕在調試器中顯示。但是,代碼實際上按照它應該的方式工作。

修復它,請蘋果。

+1

請使用最新版本的iOS試用xCode 4.2。我也遇到了你用xCode 4.0遇到的問題! – tipycalFlow

1

嘗試的

@property (nonatomic,retain) CellBackgroundView *customBackgroundView; 

代替strong,看看是否有幫助...這似乎是一個內存分配問題

+0

雖然沒有區別,好主意。我也試過'分配',也沒有這樣的運氣。 –

+0

你也必須綜合這個屬性......否則你會得到一個警告 – tipycalFlow

+0

是的,它也是合成的。我甚至嘗試寫我自己的二傳手和吸氣者,認爲這是搞砸了。不過,同樣的行爲! –

0

我改變了類型爲一個UIView。我拿走了財產併合成了聲明。我'清理'了這個項目。

所以我的代碼現在只是:

@interface CustomCell : UITableViewCell { 

    UIView *customBackgroundView; 

} 

// m-file 

customBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)]; 


結果:這是行不通的。 customBackgroundView仍然爲零。我的結論是,無論我是瘋了還是X代碼都壞了。

+0

哈哈...清理項目,然後重新啓動它,然後......沒有了XCode有時 – tipycalFlow

+0

行動起來@tipycalFlow清洗和重新啓動好幾遍了... :) –

+0

的NSLog直接[UIView的頁頭] initWithFrame:方法CGRectMake(10,10 ,10,10)]看看它是否爲零(不應該)。如果不是零,請嘗試將customBackgroundView更改爲NSString並使用customBackgroundView = @「My string」; – jptsetung

相關問題