2012-10-07 3 views
1

사용자 정의 UITableViewCells을 설정하려고합니다. 나는 아무 문제 backgroundView을 설정할 수 있습니다,하지만 난 selectedBackgroundView을 설정하면, 셀의 배경은 흰색이됩니다 만 선택한 배경이 보인다 :설정 셀을 선택한 배경보기가 백그라운드보기를 제거합니다.

- (void) createCell: (UITableViewCell*)cell onRow: (NSUInteger)row 
{ 
UIImageView* bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_background_red.png"]]; 
cell.backgroundView = bgImage; 
cell.selectedBackgroundView = bgImage; 
cell.textLabel.hidden = YES; 

UILabel* titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(20, CGRectGetHeight(cell.frame)/2, 200, 50)]; 
titleLabel.text = [[self.ruleList objectAtIndex: row] objectForKey: TitleKey]; 
titleLabel.backgroundColor = [UIColor clearColor]; 
[cell.contentView addSubview: titleLabel]; 

} 
+2

backgroundView 및 selectedBackgroundView에 대해 동일한 이미지를 설정하기 때문에. – Charan

+0

@sreecharan welp가 효과가있었습니다. 테스트를 위해서만했는데 나쁜 테스트였습니다. -__- 고맙습니다. – Chris

+0

또한 셀 또는 ImageView의 프레임을 설정하지 않았습니다. initWithImage 대신에 initWithFrame을 수행 한 다음 imageView.image를 수행하십시오. – xCoder

답변

3

을 당신은 backgroundView 및 selectedBackgroundView 모두 같은 이미지를 설정한다.

이렇게하면 두 가지가 겹쳐져 흰색 배경이 흰색으로 표시되거나 선택한 배경 만 볼 수 있습니다.

관련 문제