2017-09-01 37 views
0

我有一个tableView包含一个标签,图像和UIVIew与红色的背景颜色。当单元格被选中时,如何停止UIView的背景颜色消失?

这是我的tableView一排的照片,显示一个标签,图像和具有红色背景颜色的UIView

This is a picture of a row in my tableView which displays a label, image and a UIView that has a red background colour

但每当我选择一个单元格,的背景颜色UIView的消失,所有我能看到的是标签和图像

这是在同一行,当我选择它

This is the same row when I select it

我想知道是否有办法阻止视图的背景颜色从选中单元格时消失。

+1

cell.seletionStyle萃取= .none AUR参阅https://stackoverflow.com/questions/30233468/disable-the-uitableview-highlighting-but-allow-the-selection-of-individual-细胞 –

回答

0

这是因为单元格选择样式设置为默认值,因此将UITableViewCell选择样式更改为无。

目标C:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

斯威夫特3:

cell.selectionStyle = .none 

如果要通知用户已经选择了小区,维护它包含indexpath对象名单的NSArray的属性。在委托方法didSelectRowAtIndexPath方法上更新NSArray

在的cellForRowAtIndexPath方法变更背景颜色,如果在NSArray

最后上didSelectRowAtIndexPath方法重新加载所选择的行中存在indexpath。

+0

好的,谢谢!但是出于用户交互的目的,我如何向用户提供他/她已做出选择的反馈? –

0

试试这个:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     //Just add this below line didSelectRowAt 
     tableView.deselectRow(at: indexPath, animated: true) 

} 
0

这是一个好一点。我从MBProgressHUD/Demo

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
      [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     }); 
    } 
相关问题