shudhanshu pradhan
shudhanshu pradhan

Reputation: 35

Resizing table's height dynamically

Can someone suggest a way to change a table heights as per the content of a array? If an array has 1 data element then the table should show only one cell and if the array has 5 data elements or more then it should show that number of cells.

Upvotes: 1

Views: 580

Answers (2)

trojanfoe
trojanfoe

Reputation: 122391

To dynamically change the cell height, check-out this tutorial.

To change the UITableView height, you can do:

CGRect r = [tableView bounds];
[tableView setBounds:CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height + 48)];

Upvotes: 0

beryllium
beryllium

Reputation: 29767

If we assume that default height of row is 44px, then you can calculate table height like this

int heightTable = 44 * [array count];

If you have another row height, then check heightForRowAtIndexPath delegate method. If your table also contain header/footer/sections, then check heightForHeaderInSection and heightForFooterInSection methods.

Upvotes: 1

Related Questions