0
일부 코드를 정리하고 그렇게하는 데 문제가 있습니다. 나는 uitableviewcell에 나타나는 1-5 순위가 있습니다. 셀에는 별 이미지를 가리키는 5 개의 이미지 뷰가 있습니다. starYellow.png 및 starGrey.png가 있습니다. 순위가 3/5 인 경우 셀은 star1, star2, star3을 starYellow.png 및 star4, star5를 starGrey.png로 설정해야합니다.루프에서 propertyName + 1을 동적으로 참조하십시오.
나는 루프 1-5의 반복 인 속성 별 % i을 참조하는 데 문제가 있습니다. 나는 [셀 setValue : starYellow forKey : [NSString stringWithFormat : @ "star % i.image", i]];와 같은 것을 어떻게하는지 알아낼 수 없다. 여기
는if (book.ratingOnline) {
[cell.ratingView.layer setOpacity:1.0f];
for (int i = 1; i <= 5; i++) {
if (i == 1) {
if (book.ratingOnline >= i) { [cell.star1 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
else { [cell.star1 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
}
else if (i == 2) {
if (book.ratingOnline >= i) { [cell.star2 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
else { [cell.star2 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
}
else if (i == 3) {
if (book.ratingOnline >= i) { [cell.star3 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
else { [cell.star3 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
}
else if (i == 4) {
if (book.ratingOnline >= i) { [cell.star4 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
else { [cell.star4 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
}
else if (i == 5) {
if (book.ratingOnline >= i) { [cell.star5 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
else { [cell.star5 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
}
}
}
감사합니다 .. I 최적화 할 코드입니다.
을 할 수있는 시작 참조 할 Cell.h
에
,있는 NSArray에있는 모든 별을 추가! 나는 당신이 그런 속성을 참조 할 수 있는지 몰랐습니다. objectAtIndex : i를 i-1로 변경하여 루핑에 대한 올바른 경계를 처리하고 트릭을 수행합니다. – tknp