我想改變我的單元格背景色更改自定義背景色tableViewCell
我看其他的問題,但他們不符合我的情況
我想做一個通知的tableView
例如,如果用戶已經閱讀細胞,細胞的背景顏色將變爲白色
如果不是,顏色爲黃色
在開始
我設置
-(void)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
if(read[[indexPath row]])
[cell.backView setBckgroundColor:[UIColor whiteColor];
else
[cell.backView setBckgroundColor:[UIColor redColor];
}
它的工作原理的顏色,然後我想改變顏色
tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
read[[indexPath row]] = yes;
[cell.backView setBckgroundColor:[UIColor whiteColor];
cell.name.text = @"test";
}
它也能工作
但如果我選擇其他細胞,它改變爲原始顏色
它似乎只能改變一個單元的顏色相同時間
不管我用
cell.backgroundColor
cell.contentView.backgroundColor
cell.backView
它得到相同的結果,誰能幫助我
編輯4/20 20:13
我設置
閱讀tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
對不起方向,我更新代碼
,我選擇其他細胞後,我不叫[重裝的tableView]
,所以我不認爲這是什麼原因
順便說一句,一切都(E 。克標籤)可以改變,但背景顏色
,如果我選擇小區時,它通過導航
答跳轉到其他屏幕
結論第一
tableView: cellForRowAtIndexPath: is well
和
tableView: willDisplayCell: is well too
他們都可以改變背景顏色
但執行時需要制定新的細胞或重裝的tableView
我還是搞不清爲什麼我可以在didselectionRowAtIndexPath 更改標籤,但我不能改變顏色
我這樣做,但它不起作用,我再次編輯代碼感謝 – jim