왜 여기에서 왜 그런 일이 일어나는지 알 수 없습니다. 색을 변경하기 위해 목표로 삼을 특정 색인을 식별합니다. 그리고 내부 :indexpath.row == ...를 사용하여 색상 별 셀의 텍스트 UITableView, 둘 이상의 셀에 색상 지정
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
나는 다음과 같은 실행
if ([savedPRIndex intValue] == indexPath.row) {
[customCell togglePR:TRUE];
NSLog(@"TRUE");
}else{
[customCell togglePR:FALSE];
}
사용자 정의 셀에서
- (void)layoutSubviews{
[super layoutSubviews];
CGFloat xPosition = 20.0f; // Default text position
if(prToggle){
xPosition = -20.0f;
cellText.textColor = [UIColor colorWithRed:0x24/255.0 green:0x9e/255.0 blue:0xd6/255.0 alpha:1.0];
UIImage* img = [UIImage imageNamed:@"pr_icon.png"];
CGRect rect = CGRectMake(272.0f, 14.0f, img.size.width/2, img.size.height/2);
UIImageView* imgView = [[UIImageView alloc] initWithFrame:rect];
[imgView setImage:img];
[self addSubview:imgView];
[imgView release];
}
CGRect textLabelFrame = self.cellText.frame;
textLabelFrame.origin.x = xPosition;
self.cellText.frame = textLabelFrame;
}
-(void)togglePR:(BOOL)TF{
prToggle = TF;
}
정의 셀 togglePR은 텍스트 색상을 변경할 수있는 유일한 장소입니다, 사람이 어떤 아이디어?
무슨 일이 일어나는지 해독하는 데 도움이 될 경우 더 많은 코드를 게시 할 수 있습니다.
추가 코드
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
CustomCell *customCell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (customCell == nil) {
customCell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"savedPRIndex : %@", savedPRIndex);
NSLog(@"Index Path : %i", indexPath.row);
[customCell togglePR:[savedPRIndex intValue] == indexPath.row];
// Configure the cell...
customCell.cellText.text = [[toShow objectAtIndex:indexPath.row] objectForKey:@"Value"];
customCell.cellPower.text = [[toShow objectAtIndex:indexPath.row] objectForKey:@"PowerValue"];
customCell.cellSplit.text = [[toShow objectAtIndex:indexPath.row] objectForKey:@"Split"];
return customCell;
}
세포를 재사용 할 수 있습니다. 또한 뷰의 수명 동안 여러 번 호출 될 수 있기 때문에'-layoutSubviews'에 뷰를 추가해서는 안됩니다. 표 셀에는 이미 이미지보기가 있으므로 어쨌든이를 사용해야합니다. –