Set row height of a UITableView according to the cell in that row

HanXu

I want to adjust the row height of a UITableView according to the cell in that row.

Initially, I tried to use

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

However, the problem is, when the table is loading, the calling flow is seemed to be:

First call:

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

Then call:

(UIViewTableCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

which means, before my cell is generated, I have to tell the table the height of its row.

However, what I want is exactly the opposite, i.e., after my cell is generated, I tell the table the height of this rows.

Is there any method to achieve this?

JPetric

Make an array of heights for every row based on the data from tableView: cellForRowAtIndexPath: and in the tableView heightForRowAtIndexPath: just take the height value from that array.

Declare in your implementation file:

NSMutableArray *heights;

In viewDidLoad: initialise it:

heights = [NSMutableArray array];

In tableView: cellForRowAtIndexPath: set the height for each row:

[heights addObject:[NSNumber numberWithFloat:HEIGHT]];

And in the tableView heightForRowAtIndexPath: return required height:

return [heights objectAtIndex:indexPath.row];

This should work because tableView: cellForRowAtIndexPath: is called for every cell and then for every cell tableView heightForRowAtIndexPath: is called.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHPExcel: Set row height in pixels according to image

From Dev

PHPExcel: Set row height in pixels according to image

From Dev

Increase the main tableview row height according to the custom cell

From Dev

UITableView: automatically set height for the row and fix it with max height constant

From Dev

UITableView dynamic cell heights - reload height for single row

From Dev

Dynamic row height in UITableView using custom cell from xib

From Dev

UITableView deleting row reduced table row height

From Dev

UITableView default row height Xcode

From Dev

angularjs ng-grid how to set row or cell height

From Dev

How to set minimum height of row in prawn Table cell

From Dev

iOS 7/8 UITableView Cell: Two UILabels with dynamic height with auto layout for variable row height

From Dev

If no Image, change row cell height

From Dev

If no Image, change row cell height

From Dev

Row Height of UITableView Custom Cell doesn't update, Swift iOS8

From Dev

Adjust the height of all panels in a row according to the content

From Dev

Row height proportion according to window size changes

From Dev

Protect row according to the data in cell (Yes/No)

From Dev

Protect row according to the data in cell (Yes/No)

From Dev

Repeat a row according to the specific cell value in SQL

From Dev

How to set height constraint of UITableView according to dynamic height cells?

From Dev

Set height of a specific cell in my UITableView

From Dev

set all div's height similar according to their first div in the row using javascript object

From Dev

Dynamic UITableView row height using UIStackView?

From Dev

How to resize the UITableView row height in Objective C

From Dev

Accessing the Row Height in Dynamic UITableView Prototypes

From Dev

How to set row height of QTableView?

From Dev

UITableView - insert new row by tapping on existing cell

From Dev

Set Focus on row by cell value

From Dev

Set row height depend on JTextArea height

Related Related

  1. 1

    PHPExcel: Set row height in pixels according to image

  2. 2

    PHPExcel: Set row height in pixels according to image

  3. 3

    Increase the main tableview row height according to the custom cell

  4. 4

    UITableView: automatically set height for the row and fix it with max height constant

  5. 5

    UITableView dynamic cell heights - reload height for single row

  6. 6

    Dynamic row height in UITableView using custom cell from xib

  7. 7

    UITableView deleting row reduced table row height

  8. 8

    UITableView default row height Xcode

  9. 9

    angularjs ng-grid how to set row or cell height

  10. 10

    How to set minimum height of row in prawn Table cell

  11. 11

    iOS 7/8 UITableView Cell: Two UILabels with dynamic height with auto layout for variable row height

  12. 12

    If no Image, change row cell height

  13. 13

    If no Image, change row cell height

  14. 14

    Row Height of UITableView Custom Cell doesn't update, Swift iOS8

  15. 15

    Adjust the height of all panels in a row according to the content

  16. 16

    Row height proportion according to window size changes

  17. 17

    Protect row according to the data in cell (Yes/No)

  18. 18

    Protect row according to the data in cell (Yes/No)

  19. 19

    Repeat a row according to the specific cell value in SQL

  20. 20

    How to set height constraint of UITableView according to dynamic height cells?

  21. 21

    Set height of a specific cell in my UITableView

  22. 22

    set all div's height similar according to their first div in the row using javascript object

  23. 23

    Dynamic UITableView row height using UIStackView?

  24. 24

    How to resize the UITableView row height in Objective C

  25. 25

    Accessing the Row Height in Dynamic UITableView Prototypes

  26. 26

    How to set row height of QTableView?

  27. 27

    UITableView - insert new row by tapping on existing cell

  28. 28

    Set Focus on row by cell value

  29. 29

    Set row height depend on JTextArea height

HotTag

Archive