8

I need to change dynamically the height of a uitableview inside my view.

I tried with this code inside the viewDidLoad:

self.theTable.rowHeight = 90;
self.theTable.contentSize = CGSizeMake(320,900); 

The first line works and the height is changed, but the second doesn't work!

How can I do this?

Jack
  • 13,571
  • 6
  • 76
  • 98
ghiboz
  • 7,863
  • 21
  • 85
  • 131
  • Take a look at ... http://stackoverflow.com/questions/1318030/how-do-i-resize-the-uitableviews-height-dynamically – Sai Jul 08 '11 at 19:21

3 Answers3

14

You can try resetting the bounds like this:

CGRect bounds = [tableView bounds];
[tableView setBounds:CGRectMake(bounds.origin.x, 
                            bounds.origin.y, 
                            bounds.size.width, 
                            bounds.size.height + 20)];
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
8

This worked for me.

self.myTableView.frame = CGRectMake(0,40,320,480);
Jason
  • 650
  • 2
  • 10
  • 33
2

Please note that you can change the height of a non-autolayout UITableView by simply adjusting it's frame in viewDidAppear or viewDidLoad.

However, if you want to change the tableView's height after this point (for example, when someone taps a button) then that is not possible for tableViews created in Storyboard. You CAN change the height after the table is loaded for tableViews created programmatically.

Travis M.
  • 10,930
  • 1
  • 56
  • 72