1

レコードを縦に並べて表示したいUITableViewCell.

これが私のコードです:

cell.textLabel.text=[NSString stringWithFormat:@"%d %@ %@",objProp.contid,objProp.contname,objProp.contno];

このように自分の記録を表示したいと思います。

1  

sanjeet

9876556789
4

2 に答える 2

2

私が個人的にこれに取り組む方法は次のとおりです。

カスタム UITableViewCell サブクラスを作成します。UITableViewCell に 3 つのラベルを垂直に配置します。

self.labelA     = [[UILabel alloc] init];
self.labelB     = [[UILabel alloc] init];
self.labelC     = [[UILabel alloc] init];
NSDictionary *viewsDictionary = @{@"labelA" : self.labelA,
                                  @"labelB" : self.labelB,
                                  @"labelC" : self.labelC};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[labelA]-|"
                                                                         options:kNilOptions
                                                                         metrics:nil
                                                                           views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[labelA]-[labelB]-[labelC]-|"
                                                                         options:NSLayoutFormatAlignAllLeading | NSLayoutFormatAlignAllTrailing
                                                                         metrics:nil
                                                                           views:viewsDictionary]];

次に、各ラベルに適切なラベルを設定します。

あなたがやろうとしているのは、デフォルトの UITableViewCell の textLabel を、新しい行を導入できるように設定することだと思います。例えば:

UITableViewCell *tableViewCell;
tableViewCell.textLabel.numberOfLines   = 3;
tableViewCell.textLabel.lineBreakMode   = kNilOptions;
tableViewCell.textLabel.text            = [[NSString alloc] initWithFormat:@"%@\n%@\n%@", variableA, variableB, variableC];

私が言ったように、より良い方法は、カスタム UITableViewCell サブクラスを作成することです。

于 2013-11-12T08:44:40.860 に答える
1

tableviewcell縦方向に表示するには、カスタムを作成する必要があります。ストーリーボードを使用している場合は、テーブルビュー セルのコンテンツ ビューに 3 つのラベルをドラッグし、各ラベルに異なるタグを付けて、[cell viewWithTag:]内部でメソッドを使用します。cellForRowAtIndexPath:

例:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];


    UILabel *id = (UILabel *)[cell viewWithTag:1];
    id.text = [NSString stringWithFormat=@"%d",objProp.contid];

    UILabel *name = (UILabel *)[cell viewWithTag:2];
    name.text = [NSString stringWithFormat=@"%@",objProp.contname];

    UILabel *contact = (UILabel *)[cell viewWithTag:3];
    contact.text = [NSString stringWithFormat=@"%@", objProp.contno];

    return cell;
}
于 2013-11-12T08:40:22.797 に答える