문제 설명
셀이 선택되면 UIImageView가 사라지지만 UILabel은 사라지지 않습니다. (UIImageView disappears but not UILabel when cell is selcted)
셀이 스토리보드에서 만들어지고 IBOutlet과 연결될 때 UILabel 및 UIImageView가 있는 사용자 지정 UITableview 셀이 있습니다. 셀을 선택하면 이미지 보기의 배경이 선택 색상으로 변경됩니까? UIImageView의 배경색을 동일하게 유지하려면 어떻게 해야 하나요?
감사합니다
참조 솔루션
방법 1:
Try call:
cell.selectionStyle = UITableViewCellSelectionStyleNone
in cellForRowAtIndexPath
.
And (optionally) override:
‑ (void)setSelected:(BOOL)selected animated:(BOOL)animated
swift:
override func setSelected(selected: Bool, animated: Bool)
Swift Example usage:
override func setSelected(selected: Bool, animated: Bool) {
if selected {
yourView.alpha = 0.5
} else {
yourView.alpha = 1.0
}
}
You can also change your view's alpha inside animateWithDuration
block:
override func setSelected(selected: Bool, animated: Bool) {
UIView.animateWithDuration(0.3, animations: {
if selected {
yourView.alpha = 0.5
} else {
yourView.alpha = 1.0
}
})
}
Obj‑C example usage:
#import "YourTableViewCell.h"
@implementation YourTableViewCell
‑ (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
//your code
// example: yourView.backgroundColor = [UIColor greenColor];
}
‑ (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:YES];
//your code
// example: yourView.backgroundColor = [UIColor greenColor];
}
@end
방법 2:
You can change you cell's imageView in ‑didSelectRowAtIndexPath
of you UITableView
‑(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//get the cell from the selected row.
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
//change custom cell's imageView to desired backgroundColor
selectedCell.imageView = [UIColor clearColor];
}
And don't forget to implement UITableViewDelegate
and UITableViewDatasource
방법 3:
I think it might be happening due to tableviewcell selection. Just use the below code snippet
‑ (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableview deselectRowAtIndexPath:indexPath animated:YES];
}
This might help you. If not then please share the info of your implementation for this.
방법 4:
you might have set the background color of the image view to clear color.
(by tim blue、zuziaka、Ty Lertwichaiworawit、Sabby、Sandhil Eldhose)