我有一种情况,我已将其放置在同一位置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;