0

同じ位置のテーブルビューセルに配置UILabelした状況があり、代わりに配置されます。UITextView問題は、テーブルビューをスクロールすると、ラベルとテキストビューが一致しない(重複する)ことです。以下はcellForRowAtIndexPathコードです。

static NSString *CellIdentifier = @"CellIdentifier";
    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        //cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
        tableView.separatorColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"line_left_table.png"]];

        availableTtimeSlotLbl=[[UILabel alloc] initWithFrame:CGRectMake(10,10,200,40)];
        availableTtimeSlotLbl.backgroundColor=[UIColor clearColor];
        availableTtimeSlotLbl.textColor=[UIColor colorWithRed:17/255.0 green:61/255.0 blue:83/255.0 alpha:1];
        availableTtimeSlotLbl.font=[UIFont boldSystemFontOfSize:18];
        availableTtimeSlotLbl.tag=1;
        [cell.contentView addSubview:availableTtimeSlotLbl];


        durationLbl=[[UILabel alloc] initWithFrame:CGRectMake(230,10, 250,45)];
        durationLbl.backgroundColor=[UIColor clearColor];
        durationLbl.textColor=[UIColor colorWithRed:17/255.0 green:61/255.0 blue:83/255.0 alpha:1];
        durationLbl.tag=2;
        durationLbl.font=[UIFont systemFontOfSize:18];
        [cell.contentView addSubview:durationLbl];

        statusLbl=[[UILabel alloc] initWithFrame:CGRectMake(500,10,250,40)];
        statusLbl.backgroundColor=[UIColor clearColor];
        statusLbl.textColor=[UIColor colorWithRed:17/255.0 green:61/255.0 blue:83/255.0 alpha:1];
        statusLbl.tag=3;
        statusLbl.font=[UIFont boldSystemFontOfSize:18];
        [cell.contentView addSubview:statusLbl];

        statusTxtVw=[[UITextView alloc] initWithFrame:CGRectMake(500,10,250,40)];
        statusTxtVw.backgroundColor=[UIColor clearColor];
        statusTxtVw.textColor=[UIColor colorWithRed:17/255.0 green:61/255.0 blue:83/255.0 alpha:1];
        statusTxtVw.tag=4;
        statusTxtVw.font=[UIFont boldSystemFontOfSize:18];
        [cell.contentView addSubview:statusTxtVw];

        }

    UILabel *slot=(UILabel *)[cell.contentView viewWithTag:1];
    NSString *slotStr= [[scheduleAppointmentAry objectAtIndex:indexPath.row]valueForKey:@"SlotTime"];
    slot.text=slotStr; 

    UILabel *duration=(UILabel *)[cell.contentView viewWithTag:2];
    NSString *durationStr= [[scheduleAppointmentAry objectAtIndex:indexPath.row]valueForKey:@"Station"];
    duration.text=durationStr;

    NSString *statusStr= [[scheduleAppointmentAry objectAtIndex:indexPath.row]valueForKey:@"Status"];
    UILabel *status=(UILabel *)[cell.contentView viewWithTag:3];
    UITextView *statusTxtView = (UITextView *) [cell.contentView viewWithTag:4];

    if ([statusStr isEqualToString:@"Schedule"]) {

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        statusTxtView.text = statusStr;

    }
    else if([statusStr isEqualToString:@"Unavailable"]) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        status.text=statusStr;
    }

    return cell;
4

1 に答える 1

0

セルが再利用されるため、行の内容が繰り返されます。それらを適切にリセットする必要があります。

if ([statusStr isEqualToString:@"Schedule"]) {

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    statusTxtView.text = statusStr;
    // ADDED: Reset status label
    status.text = nil;
}
else if([statusStr isEqualToString:@"Unavailable"]) {

    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    status.text=statusStr;
    // ADDED: Reset status text view
    statusTxtView.text = nil;
}
于 2012-08-10T09:11:15.640 に答える