셀이 선택되면 UIImageView가 사라지지만 UILabel은 사라지지 않습니다. (UIImageView disappears but not UILabel when cell is selcted)


문제 설명

셀이 선택되면 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 bluezuziakaTy LertwichaiworawitSabbySandhil Eldhose)

참조 문서

  1. UIImageView disappears but not UILabel when cell is selcted (CC BY‑SA 2.5/3.0/4.0)

#uitableview #iphone #objective-c #iOS #uiimageview






관련 질문

레코드 삭제 중 오류 발생, 포착되지 않은 예외 'NSInternalInconsistencyException'으로 인해 앱 종료 (error while deleting records,Terminating app due to uncaught exception 'NSInternalInconsistencyException')

IOS 7에서 편집 상태의 셀을 반환하는 dequeueReusableCellWithIdentifier (dequeueReusableCellWithIdentifier returning cells in editing state in IOS 7)

UITableViewCell 탭 호버 (UITableViewCell tap hover)

ios swift tableview 셀 사이의 공간을 어떻게 변경할 수 있습니까? (How can I change the space between tableview cells ios swift)

테이블 뷰 셀을 선택할 때 뷰 컨트롤러를 푸시할 수 없습니다. (Can't push my view controller when I select a table view cell)

셀이 선택되면 UIImageView가 사라지지만 UILabel은 사라지지 않습니다. (UIImageView disappears but not UILabel when cell is selcted)

UITableView의 테두리를 설정하는 방법은 무엇입니까? (How to set a border for UITableView?)

plist에서 특정 데이터를 가져오는 UITableView(탐색 템플릿을 사용하지 않음) (UITableView (not using Navigation Template) getting specific data from plist)

searchBar의 일반 텍스트 버튼에 액세스하는 방법은 무엇입니까? (How to access searchBar's clear text button?)

'NSInternalInconsistencyException', 이유: '범위를 벗어난 섹션(0)에 대한 행 수를 요청했습니다.' ('NSInternalInconsistencyException', reason: 'Requested the number of rows for section (0) which is out of bounds.')

UITableViewCell에서 키보드 탭을 숨기는 UITapGestureRecognizer (UITapGestureRecognizer to hide keyboard taps on UITableViewCell)

특정 UITableViewCells에 고유한 삽입을 추가하는 방법은 무엇입니까? (How to add unique insets to specific UITableViewCells?)







코멘트