J'ai utilisé un UINavigationController pushViewController pour présenter un ViewController, sur la vue du viewcontroller, il y a un UITablView. J'ai utilisé les codes ci-dessous pour dessiner UILabel sur UITableViewCell, mais il ne s'affiche pas, seulement quand j'appuie sur la ligne où se trouve l'UIlabel, il apparaît, si je tape une autre ligne, il disparaît à nouveau.étrange problème dessiner une étiquette sur UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier1 = @"CellTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier1 ];
if (cell == nil)
{
cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:SimpleTableIdentifier1] autorelease];
switch([[myArray objectAtIndex:indexPath.row] getValueType])
{
case _PSToggleSwitchSpecifier:
{
UISwitch *switchview=[[UISwitch alloc]init];
switchview.tag=11106 ;
cell.accessoryView= switchview;
//switchview.frame=CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
//[cell.contentView addSubview:switchview];
[switchview addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[switchview release];
break;
}
case _PSMultiValueSpecifier:
{
cell.accessoryType= UITableViewCellAccessoryDisclosureIndicator;//
//draw a label, but actually it does display,
UILabel *labelCell =[ [UILabel alloc]init];
[labelCell setTag:11101];
labelCell.frame = CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
[labelCell setBackgroundColor:[UIColor clearColor]];
labelCell.textAlignment=UITextAlignmentRight;
[labelCell setFont:[UIFont systemFontOfSize:18.0]];
[labelCell setTextColor:[UIColor blackColor]];
[cell.contentView addSubview:labelCell];
[labelCell release];
break;
}
}
}
[email protected]"test";
switch([[myArray objectAtIndex:indexPath.row] getValueType])
{
case _PSToggleSwitchSpecifier:
{
cell.accessoryType=UITableViewCellAccessoryNone;//
UISwitch *tem=(UISwitch*) [cell.contentView viewWithTag:11106];//cell.accessoryView;//
tem.on= true;
break;
}
case _PSMultiValueSpecifier:
{
UILabel *newLabelCell=(UILabel*)[cell.contentView viewWithTag: 11101];//intV];
[email protected]"Items";//it should display, but actually not, only when I tap the row "didselect" the text display
break;
}
};
return cell;
}
Dans les codes ci-dessus UISwitch sont affichés, mais si j'utilise des codes
switchview.frame=CGRectMake(80.9f,15.0f,80.0f,23.0f) ;
[switchview addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:switchview];
pour remplacer cell.accessoryView= switchview;
UISwitch sera la même chose que UILabel
Bienvenue tout commentaire
Merci
InterDev