我試圖更改標籤的text color
在單元格時當前日期== Facebook的生日名單日期。更改的UILabel的文本顏色中的UITableViewCell
在cellForRowAtIndexPath:
ID這樣做
if([curdatemonthstring isEqualToString:[[totalbirthlistArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]])
{
[nameLabel setTextColor:[UIColor purpleColor]];
}
這工作來改變顏色,但是當我把它的滾動變回舊的顏色。我怎樣才能解決這個問題?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"SimpleTableItem";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:simpleTableidentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableidentifier]autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[[[cell contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
contentview = [[[UIView alloc]init] autorelease];
[contentview setFrame:CGRectMake(0, 0,320,80)];
//Display Friends Name
nameLabel = [[[UILabel alloc] init]autorelease];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[nameLabel setFrame:CGRectMake(76, 5, 200, 45)];
[nameLabel setFont:[UIFont fontWithName:@"Politica" size:20]];
[nameLabel setText:[[[monthdataArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]objectForKey:@"name"]];
if([curdatemonthstring isEqualToString:[[totalbirthlistArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]])
{
[nameLabel setTextColor:[UIColor purpleColor]];
}
[contentview addSubview:nameLabel];
[cell.contentView addSubview:contentview];
return cell;
[birthdaylist reloadData];
}
請提供完整的代碼。 –
我認爲您已經將它寫入了if(cell == nil)的條件 – SRI
明確顯示您在創建單元格的位置,重置該單元格的顏色很可能是因爲未正確創建單元格。 –