0

CustomCellViewテーブルビューのセルのカスタムビューがあります。私はUIButtonxibに持っていて、xibでデフォルトのフレームに設定しています。

( MainViewController)viewDidLoad

// Get nib for custom cell
UINib *nib = [UINib nibWithNibName:@"CustomFeedCell" bundle:nil];
[self.mainTableView registerNib:nib forCellReuseIdentifier:@"CustomFeedCell"];

cellForRow で...

CustomFeedCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:@"CustomFeedCell"];

// here i need to set UIButton frame (height) depending on image height.
// I have tried diferent ways and it always return height set in CustomCellView xib
4

2 に答える 2

0

ボタンや画像などをUIView動的に作成する場合は、viewDidLoad:メソッドを使用する必要があり、xibs は使用しません。

于 2013-04-29T12:20:06.547 に答える
0

あなたの質問から私が理解しているのは、テーブルビューセルにあるボタンの動的な高さを設定する際に問題があるということです。セルの高さよりも大きい場合もあれば、セルの高さよりも小さい場合もあります。それに応じて調整する必要があります。正しい ?

それが問題である場合は、デリゲート tableView:heightForRowAtIndexPath で各テーブルビュー セルの高さを設定できます。

なので

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [indexPath row] * 20; // your desired height
}

これで問題が解決することを願っています。

于 2013-04-30T05:01:10.830 に答える