2010-11-30 16 views
2

Je le code et donne le résultat de la capture d'écran ci-dessous. C'est dans la tableView: cellForRowAtIndexPath: méthode. Je ne sais pas pourquoi le texte au-dessus des barres ne montre pas. Quelqu'un a-t-il une idée? Je vous remercie.UITableViewCell ne pas montrer dans les UILabel

cell.textLabel.text = @""; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.textAlignment = UITextAlignmentLeft; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    UILabel * label = [[UILabel alloc] initWithFrame: cell.textLabel.frame]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.text = [NSString stringWithFormat:@"%.1f%% (%i)",([[options_votes objectAtIndex: [indexPath row]] intValue] * 100.0/total_votes),[[options_votes objectAtIndex: [indexPath row]] intValue]]; 
    NSLog(@"%@",[NSString stringWithFormat:@"%.1f%% (%i)",([[options_votes objectAtIndex: [indexPath row]] intValue] * 100.0/total_votes),[[options_votes objectAtIndex: [indexPath row]] intValue]]); 
    label.textAlignment = UITextAlignmentRight; 
    [cell.contentView addSubview:label]; 
    [label release]; 
    label = [[UILabel alloc] initWithFrame: cell.textLabel.frame]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.text = [options objectAtIndex:[indexPath row]]; 
    NSLog(@"%@",[options objectAtIndex:[indexPath row]]); 
    label.textAlignment = UITextAlignmentLeft; 
    [cell.contentView addSubview:label]; 
    [label release]; 
    UIImageView * image_view = [[UIImageView alloc] initWithImage:nav_delegate->back_bar]; 
    image_view.frame = CGRectMake(10, 44, 280, 10); 
    [cell.contentView addSubview:image_view]; 
    [image_view release]; 
    image_view = [[UIImageView alloc] initWithImage:nav_delegate->blue_bar]; 
    image_view.frame = CGRectMake(10, 44, 5 + [[options_votes objectAtIndex: [indexPath row]] intValue] * 275.0/total_votes, 10); 
    [cell.contentView addSubview:image_view]; 
    [image_view release]; 

alt text

Répondre

4

Juste un coup de poignard dans le noir, mais parce que vous avez fait cell.textLabel.text = @"";, il aurait pu reculait le cadre du Textlabel il à une largeur de 0. Essayez de créer vos étiquettes à base de d'un cadre que vous savez être d'une taille visible correcte.

+0

merci D'accord. Cela fonctionne ailleurs en utilisant ce cadre. Je vais essayer de le changer si –

+0

Cheers. Cela a fonctionné un régal. –

1

Pour afficher vos 2 étiquettes, vous pouvez utiliser ce code:

cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    if (indexPath.row == 0) { 
     UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(11, 10, 280, 25)]; 
     label1.backgroundColor = [UIColor clearColor]; 
     label1.text = @"Your Text Here"; 
     label1.textAlignment = UITextAlignmentRight; 
     [cell.contentView addSubview:label1]; 
     [label1 release]; 
    } 
    if (indexPath.row == 1) { 
     UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(11, 10, 280, 25)]; 
     label2.backgroundColor = [UIColor clearColor]; 
     label2.text = @"Your Text Here"; 
     label2.textAlignment = UITextAlignmentLeft; 
     [cell.contentView addSubview:label2]; 
     [label2 release]; 
    } 
    if (indexPath.row == 2) { 
     // Put your imageView code here. 
    }

Remarque: si vous utilisez un tableViewCell plus grand que la taille des paramètres par défaut, 44,0, vous pouvez modifier le numéro 25 dans la méthode initWithFrame du Étiquettes.
espère que cela peut vous aider :)

+0

Merci, mais comme vous pouvez le voir sur l'image, je veux plusieurs étiquettes par ligne. De plus, dans votre code j'utiliserais une structure if ... else ou une instruction switch. –

+0

;) Cependant, vous êtes les bienvenus! – matteodv