簡體   English   中英

當用戶返回表格時自定義表格的單元格顏色

[英]Customize a table's cell color when the user is returning to the table

我為您准備了一個簡單的程序。 當用戶在選擇tableviewcell后從視圖返回時,我試圖保留默認行為。 通常,該單元格會保持藍色一會兒,以向用戶顯示所選行的位置,但是我忘記了如何對其進行自定義。 為了簡單起見,默認情況下,我所有的單元格都是綠色的,而在選擇它們時它們就會變成紅色。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    if (selected) {
        self.backgroundColor = [UIColor redColor];
    } else {
        self.backgroundColor = [UIColor greenColor];
    }
}

當用戶選擇“后退”按鈕時,該單元格不會向用戶顯示其最后選擇的單元格,在這種情況下為紅色。 我記得在控制器中有一個變量可以用來自定義它,但是我不記得它是什么。 有人可以指出我正確的方向嗎?

謝謝!

如果只想更改背景單元格的顏色,則可以創建一個新視圖,將其設置為背景色,然后將其分配給選定的背景視圖單元格。

UIView *cellSelectedBackgroundView = [[UIView alloc] init];
[cellSelectedBackgroundView setBackgroundColor:[UIColor someColor]];
[cell setSelectedBackgroundView:cellSelectedBackgroundCView];

我一直在尋找的屬性和方法是:

self.clearsSelectionOnViewWillAppear = YES;
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

感謝那些回答。

UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM