在項(xiàng)目開發(fā)過(guò)程中,UI測(cè)試反饋一個(gè)Bug,TableView行選中時(shí),行內(nèi)字體圖片發(fā)生改變。

一開始認(rèn)為是在行選中時(shí),被自動(dòng)設(shè)置成系統(tǒng)默認(rèn)的選中字體顏色,便在行選中時(shí),重新設(shè)置選中行里的文字字體顏色,并沒(méi)有什么用。后來(lái)當(dāng)tablecellview的backgroudstyle發(fā)生改變時(shí),會(huì)影響其中的subview的backgroudstyle的改變。
when the -backgroundStyle is NSBackgroundStyleDark, the view should use a light text color. Upon setting, the default implementation automatically forwards calls to all subviews that implement -setBackgroundStyle: or are an NSControl (which have NSCells that respond to -setBackgroundStyle:)
于是我在繼承的NSTableCellView類中重寫- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle禁止subview的backgroundStyle改變。
- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle
{
[super setBackgroundStyle:backgroundStyle];
if(backgroundStyle == NSBackgroundStyleDark)
{
self.textField.cell.backgroundStyle = NSBackgroundStyleLight;
self.imageView.cell.backgroundStyle = NSBackgroundStyleLight;
}
}
j