3

内容に応じてテーブルビューの行の高さを自動調整する方法や解決策はありますか?つまり、行の高さを指定せず、行の内容に応じて行の高さを指定したいのですが、そのような方法がない場合は教えてくださいデバイスの向きが変わったときに高さを変更するにはどうすればよいですか?

4

6 に答える 6

4

コンテンツの高さを見つけて使用できるようにする必要があります

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     return "your content height + your padding height value";
 }

向きを変更したら、テーブルビューをリロードするだけです。

于 2012-11-12T10:08:09.480 に答える
2

これをチェックしてください

// --dynamic cell height according to the text--
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

  NSString *text = <your text>;
  CGSize constraint = CGSizeMake(210, 20000.0f); 
  CGSize size = [text sizeWithFont:[UIFont fontWithName:@"Helvetica-Light" size:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 
  // constratins the size of the table row according to the text

  CGFloat height = MAX(size.height,60);

  return height + (15);
  // return the height of the particular row in the table view
}

お役に立てれば

オリエンテーションの編集この方法を試しましたか?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

    return YES;
}

または、テーブルセルがラベルやイメージビューなどでカスタム化されている場合は、それぞれでsetAutoresizingMask:を使用して、向きに自動調整できます。

[yourview setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
于 2012-11-12T10:08:07.297 に答える
1

あなたは実装することができます - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewのデリゲートメソッド。

あなたがそれをグーグルするならば、あなたはそれについてたくさんのチュートリアルを見つけることができるはずです。

たとえば、次のようになります。

http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/

于 2012-11-12T10:05:16.163 に答える
0

あなたが使用する必要があります:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

ええ-私はあなたがこの方法をよく知っていることを知っています、そして私はあなたの質問を注意深く読みました。

  1. 行の高さを動的に制御するには、そのデリゲートメソッドを使用する必要があります。私の提案は、テーブルビューのバックエンドデータモデルから各セルのコンテンツを調べて、そのセルに適切な数値を次のように返すことです。

NSDictionary *thisCell = (NSDictionary *)[myArray objectAtIndexPath:indexPath.row];

NSString *myCellContents = [thisCell valueForKey:@"MyStringIWantToCheckOut"];

if ([mycellContents length] > 25) {        
    return 80; 
} else {        
    return 40;
}
  1. 向きが変わる場合は、デリゲートメソッドでそれを行う必要があります。

    -(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration

その後、に発砲reloadDataTableViewます。

于 2012-11-12T10:28:07.030 に答える
0
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    switch (indexPath.row){
        case 0:
            if(indexPath.section == 0)
                //title 
                return  75;
        default:
            return 75;
    }
}
于 2014-05-09T07:33:03.053 に答える
0

func tableView(_ heightForRowAttableView:UITableView、heightForRowAt indexPath:IndexPath)-> CGFloat {return UITableViewAutomaticDimension}

行の動的な高さの場合、それ以外の場合は「UITableViewAutomaticDimension」の代わりに静的な高さを指定できます

于 2018-05-08T09:29:31.167 に答える