0

Я разрабатываю приложение, чтобы показать push-уведомление в 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 в вашей ячейке. Найдите UILabel на этом UIView. напишите cell текст на этом UILabel. Теперь установите UIView backgroundColor и cell.seletionStyle = none и UILabel backgroundColor = clear.

Теперь, в

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

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

} 

это только предположение, может быть, это поможет вам.

Смежные вопросы