質問

これはiPhone0S2.0にアクセスしてください。その回答2.1や豪雨で、地滑りや洪水なども、私は知らなかい違いに関する。

うことができるはずテキストをラップを作成することなくカスタムセルが UITableViewCell が含まれて UILabel デフォルトです。私のなかに石えびが入ってすることができるよう、その仕事場を作りたいカスタムセルが、それだけではありませんかんという名称を使うようになりたいなぜ私の現在のアプローチの方法でやらねばならない。

思い出のラベルを作成した要素から細胞の支援だけでなく文字や画像のアクセスはしませんのデビューまで必要に応じて、なんて思ったこと。

cell.text = @""; // create the label
UILabel* label = (UILabel*)[[cell.contentView subviews] objectAtIndex:0];

しか有効で、ラベルが設定 numberOfLines この(lineBreakMode)ないもの単線です。あたっぷりの高さ UILabel このテキストで表示-私は帰国大値の高さ heightForRowAtIndexPath.

役に立ちましたか?

解決

こちらはより簡単な方法でを動作させることができた

内部にお cellForRowAtIndexPath: 機能です。を作成する際には最初に一回のお客様:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}

いた行数の設定は、ラベルは0です。これで利用して多くのラインとする結果になっております。

次の部分を指定する大きさ UITableViewCell する、ということをお heightForRowAtIndexPath 機能:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText = @"Go get some text for your cell.";
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 20;
}

い20-自返されたセルの高さかちょっとしたバッファーマです。

他のヒント

更新のテルペの回答のiOS7:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText = @"Go get some text for your cell.";
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];

    NSAttributedString *attributedText =
        [[NSAttributedString alloc]
            initWithString:cellText
            attributes:@
            {
                NSFontAttributeName: cellFont
            }];
    CGRect rect = [attributedText boundingRectWithSize:CGSizeMake(tableView.bounds.size.width, CGFLOAT_MAX)
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                               context:nil];
    return rect.size.height + 20;
}

簡単なコメントに答えを記録私の経験した時も同じ問題です。も、コードエディタツールバー上の例では、テーブルはビュセルの高さ調整したものの、ラベルの内部の細胞といった調整を正確に解決したいた私の細胞からカスタムNIBファイルが 細胞の高さを調整します。

ん"設定内にNIBファイルはラップのテキスト1行のレーベル;ペン先のファイルの設定をオーバーを設定し調整内のコードです。

授業をたたく、常に意の状態のオブジェクトはその時々れない場合が作成されてい関する詳細を策定したものです。...hth誰かにする。

この追加のみのテキスト UITableView 細胞までの代表作(追加 UILabels)

1) cellForRowAtIndexPath

2) heightForRowAtIndexPath

このソリューション試験:-

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{ 
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;

    [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 
    cell.textLabel.text = [mutArr objectAtIndex:indexPath.section];
    NSLog(@"%@",cell.textLabel.text);

    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png" ]];

    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{  
    CGSize labelSize = CGSizeMake(200.0, 20.0);

    NSString *strTemp = [mutArr objectAtIndex:indexPath.section];

    if ([strTemp length] > 0)
        labelSize = [strTemp sizeWithFont: [UIFont boldSystemFontOfSize: 14.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];

    return (labelSize.height + 10);
}

この文字列 mutArr は変更可能な配列からなっていった。

編集:- この配列であった.

mutArr= [[NSMutableArray alloc] init];

[mutArr addObject:@"HEMAN"];
[mutArr addObject:@"SUPERMAN"];
[mutArr addObject:@"Is SUPERMAN powerful than HEMAN"];
[mutArr addObject:@"Well, if HEMAN is weaker than SUPERMAN, both are friends and we will never get to know who is more powerful than whom because they will never have a fight among them"];
[mutArr addObject:@"Where are BATMAN and SPIDERMAN"];

現在のtableviewsで自サイジング細胞設定の表示についてなど、

tableView.estimatedRowHeight = 85.0 //use an appropriate estimate tableView.rowHeight = UITableViewAutomaticDimension

Apple参照

また以下のソリューション。

のデータは別途定める会員:

-(NSString *)getHeaderData:(int)theSection {
    ...
    return rowText;
}

取り扱いが簡単にできる cellForRowAtIndexPath.を定義する細胞を定義するフォントを割り当てこれらの値の結果とを意味します。ことに注意 numberoflines 設定"0"というかが必要です。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UIFont *cellFont = [UIFont fontWithName:@"Verdana" size:12.0];
    cell.textLabel.text= [self getRowData:indexPath.section];
    cell.textLabel.font = cellFont;
    cell.textLabel.numberOfLines=0;
    return cell;
}

heightForRowAtIndexPath, 私は計算の高さに包まれます。のbodingサイズはの幅の細胞です。IPadことは1024.IPhone ja iPod320.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIFont *cellFont = [UIFont fontWithName:@"Verdana" size:12.0];
    CGSize boundingSize = CGSizeMake(1024, CGFLOAT_MAX);
    CGSize requiredSize = [[self getRowData:indexPath.section] sizeWithFont:cellFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
    return requiredSize.height;    
}

するこの非常に単純明快であり

[self.tableView setRowHeight:whatEvereight.0f];

用例:

[self.tableView setRowHeight:80.0f];

こ示すものではありませんの標準的なもので働きました。

みっコード速いと感じました。このコードは作業のための通常のUILabelsます。

extension UILabel {
    func lblFunction() {
        //You can pass here all UILabel properties like Font, colour etc....
        numberOfLines = 0
        lineBreakMode = .byWordWrapping//If you want word wraping
        lineBreakMode = .byCharWrapping//If you want character wraping
    }
}

今は電話だけでこのような

cell.textLabel.lblFunction()//Replace your label name 

こういうによって豊かに、短います。だ形式の UILabel (textLabel の細胞を自動計算の高さを指定する sizeToFit できます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    cell.textLabel.text = @"Whatever text you want to put here is ok";
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;
    [cell.textLabel sizeToFit];

    return cell;
}

しないほうがいいと思いままでの操作の拠点 UITableViewCell's 民間 UILabel 関係ではないかと思います。として追加できる新しい UILabel 細胞自身で使用 numberOfLinessizeToFit サイズ要ですか。のようなもの:

UILabel* label = [[UILabel alloc] initWithFrame:cell.frame];
label.numberOfLines = <...an appriate number of lines...>
label.text = <...your text...>
[label sizeToFit];
[cell addSubview:label];
[label release];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top