Я не могу понять, что здесь происходит и почему.Я идентифицирую определенный индекс, на который я хочу нацелиться, чтобы изменить цвет.А внутри:
- (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;
}
Пользовательская ячейкаместо, где текст может изменить цвет, у кого-нибудь есть идеи?
Я могу выложить больше кода, если это поможет расшифровать происходящее.
Дополнительный код
- (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;
}