UITableViewControllers會,如果他們的clearsSelectionOnViewWillAppear
屬性設置爲YES,取消對viewWillAppear中選定行。如果你不使用表格視圖控制器與設置(默認是YES,我認爲)自己動手:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
落實做了(或會)取消委託方法和解決您的色彩:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// do what you want to the cell
}
順便說一下,其他人SO建議設置該單元格的內容視圖(不cell.backgroundColor
,但cell.contentView.backgroundColor
)的顏色,並在willDisplayCell:forRowAtIndexPath:
這樣做。
我這樣做BU的backgroundColor一些reasons.that是這裏的問題 – hacker 2013-03-05 07:07:31