質問

I have UITableView where I have text OR text + images.

What I want to do the height of cell depending on the text & images.

I have fixed size of image (let's say 300 width x200 height).

Any idea how can I set height of cell based on content.

Lets say if I have text, height should be 200px and if I have text/ images, I will height 400 px.

Any idea how to set height in such situation.

役に立ちましたか?

解決

Use this UITableViewDelegate method:

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

As for the width, a table view is a view, so it inherits UIView properties. So to change the width you can change the value of bounds.size.width.

他のヒント

I would use (UITableViewDelegate method)

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

Then you can use (UITableView method)

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

To get your cell and just check either type, if you have different types for the two cells or some property or size of content and return correct height.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top