0

現在の日付== Facebookの誕生日リストの日付text colorの場合、セル内のラベルを変更しようとしています。

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 *simpleTableidentifier=@"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];




}
4

3 に答える 3

0

テーブルビューはスクロール中にセルを再利用するため、ほとんどの問題は、上記のロジックをif(!cell)条件内に記述しているためです。

于 2013-08-22T12:00:47.587 に答える