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