Reputation: 1372
I am trying to display data from a mysql database on my server. I am loading the data into a table. The problem is, I don't want this data to be the only thing on the view. I want the table to be shared with other content. Ideally, I would like the table to be able to grow and expand with how many cells their are. So if there are 3 cells, I would like it to grow to fit all 3. If there are 10, I would like it to grow to fit all 10.
It looks like Apple does this a lot. A major place I notice it is in their contacts, the phone numbers table grows and shrinks depending on how many numbers there are.
Upvotes: 11
Views: 18403
Reputation: 20551
with bellow code your tableview size decide with its content...
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height);
Upvotes: 21
Reputation: 31026
When you say "grow", I'm not sure if you mean just the number of cells or the actual dimensions of the view itself.
If it's the cell count, use tableView:numberOfRowsInSection:
in the table view's data source. If you also want the view size to change, calculate a new rectangle for it to occupy and assign that as its frame
property.
Upvotes: 0