2016-04-16 11 views
0

UITableViewCellの高さを設定してください。セットアップできません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; 
} 

このコードは、これを与える:このような

enter image description here

方法は、私を助けていませんでした:SO

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

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

、私のセットアップは、高さ小さい場合。つまり、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の非常に大きな高さに設定しても、変更されていません。上部のみが表示されます。

+0

ストーリーボード – Birendra

+0

@Birendraを使用して設定しようとしましたが、画面サイズによって高さが異なるためプログラムでセットアップしたいと考えています。 – Vyacheslav

+0

@Birendra、私はストーリーボードを使用しようとしました。とにかく同じ結果。 – Vyacheslav

答えて

0

おかげで、これらの行を追加します。私は解決策を見つけた。

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

コード:

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

私は理解していないが、私はプログラムでテーブルを宣言したとき、それは動作しませんでした。

0

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

0

ベターUIを作成するために、自動レイアウトでカスタムのUITableViewCellを使用し、すべての人にのviewDidLoadで

tableView.estimatedRowHeight = 44.0 
tableView.rowHeight = UITableViewAutomaticDimension 
+0

悲しいことに、それは助けにはなりません。 – Vyacheslav

関連する問題