0

UITableViewCell高さを設定するのを手伝ってください。

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    UILabel *l0, *l1;
    if (cell == nil) {

        CGRect f = tableView.frame;
        float sc0 = pow(dt.PHI_1, 3.f);
        float sc1 = 1. - sc0;

        CGRect z =CGRectMake(0, 0, 0, 0);//f.size.height
        CGRect r =CGRectMake(0, 0, f.size.width, f.size.height / 26.f);
        CGRect r0 =CGRectMake(0, 0, f.size.width * sc0, f.size.height / 26.f);
        CGRect r1 =CGRectMake(f.size.width * sc0, 0, f.size.width * sc1, f.size.height / 26.f);

        cell = [[UITableViewCell alloc] initWithFrame:r]
        l0 = [[UILabel alloc] initWithFrame:r0];
        l0.tag = 100;
        [cell addSubview:l0];
        l1 = [[UILabel alloc] initWithFrame:r1];
        l1.tag = 101;
        [cell addSubview:l1];
        [cell.textLabel setFrame:z];
        [cell.imageView setFrame:z];
        [cell setFrame:r];
        [cell.backgroundView setFrame:r];
    } else {
        l0 = (UILabel *)[self.view viewWithTag:100];
        l1 = (UILabel *)[self.view viewWithTag:101];
    }
    cell.backgroundColor = [[UIColor alloc]initWithWhite:.0f alpha:0.f];

    cell.imageView.hidden = YES;
        cell.textLabel.hidden = YES;
        [l0 setText:@"B"];
        l0.backgroundColor = [UIColor yellowColor];

        [l1 setText:@"TEXT"];
        l1.backgroundColor = [UIColor redColor];

        return cell;
}

このコードはこれを与えます:

ここに画像の説明を入力

このような方法は私を助けませんでした:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGRect f = tableView.frame;

    return f.size.height / 26.f;
}

SO、高さを小さく設定すると。つまりf.size.height / 26.f、透明なバーがあります。

UITableView意味:

table = [[UITableView alloc] initWithFrame:CGRectMake(x,y,w,h)];
table.dataSource = self;
[table setTag:1];
[self.view addSubview:table];

セルの高さを設定する方法を教えてください。非常に大きな高さを設定UITableViewCellしても変更されず、上部のみが表示されます。

4

3 に答える 3

0

セルのカスタム クラスを作成し、代わりにこのクラスを使用しますUITableViewCell- (void)awakeFromNib {}カスタムセルクラスでセルのプロパティを設定します。これを試して。これはあなたのために働くかもしれません。:)

于 2016-04-16T07:46:43.323 に答える
0

自動レイアウトでカスタム UITableViewCell を使用して UI を作成し、これらの行を viewDidLoad に追加することをお勧めします。

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension 
于 2016-04-16T07:50:32.073 に答える
0

みんなありがとう。解決策を見つけました。

  1. storeboard を使用して UITableView を宣言する
  2. 以下のコードを使用して高さを定義します。

コード:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CGRect f = tableView.frame;
        return f.size.height / 26.f;
    }

わかりませんが、プログラムでテーブルを宣言するとうまくいきませんでした。

于 2016-04-16T09:56:16.653 に答える