0

我正在開發一個應用程序,以在uitableview中顯示推送通知。如果用戶尚未顯示通知,則打印該通知的單元格具有灰色背景色。 因此,當鑑於如何在選中單元格時編輯uitableviewcell的背景顏色

cellForRowAtIndexPath 

方法加載我看,如果沒有顯示更改單元格的背景爲灰色,並離開它默認如果通知顯示

if([shown isEqualToString:@"no"]){ 
    cell.contentView.backgroundColor = [UIColor lightGrayColor]; 
    cell.textLabel.backgroundColor = [UIColor lightGrayColor]; 
    cell.detailTextLabel.backgroundColor = [UIColor lightGrayColor]; 
} 
cell.textLabel.text = [NSString stringWithFormat:@"Notifica del %@",data]; 
cell.detailTextLabel.text = message; 

我想改變背景顏色的通知白(相同的風格,當我不碰負載背景顏色),當用戶點擊細胞

我這樣做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSString *not = [notification objectAtIndex:indexPath.row]; 
NSArray *stringArray = [not componentsSeparatedByString:@"---"]; 
NSString *message = [stringArray objectAtIndex:0]; 
NSString *data = [stringArray objectAtIndex:1]; 
NSString *shown = [stringArray objectAtIndex:2]; 
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; 
cell.contentView.backgroundColor = [UIColor whiteColor]; 
cell.textLabel.backgroundColor = [UIColor whiteColor]; 
cell.detailTextLabel.backgroundColor = [UIColor whiteColor]; 
UIAlertView *popUp = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Notifica del %@",data] message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
[popUp show]; 
[popUp release]; 
} 

結果是所有的單元格變成完全白色(隱藏文本)和警報出現,但是當我點擊另一個單元格時,第一次點擊變得像以前一樣,新單元格變成完全白色..我該怎麼做?你可以幫我嗎?

回答

0

使UIView在您的cell.take UILabel對此UIView。在UILabel上寫下cell的文字。現在,設置爲UIView backgroundColorcell.seletionStyle =無,並且UILabel backgroundColor =清除。

現在,在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

change your view background color and uilabel color. shortly change color of cellview and cell text color 

} 

這只是一個建議,可能是它會幫助你。

相關問題