monoceres
monoceres

Reputation: 4770

Resizing UITableView (with controller) after being added as subview?

First off, I'm new to iOS development, so if the below is the wrong way to do stuff on iOS, please let me know!

My goal is to embed a UITableView (with a controller) inside another View (which also have a controller).

To do this I have:

In my parent controller I have added this code:

MeterInfoTableViewController* meterInfoTableController = [[MeterInfoTableViewController alloc] initWithNibName:@"MeterInfoTableViewController" bundle:nil];
[self addChildViewController:meterInfoTableController];
[self.container addSubview:meterInfoTableController.view];
[self.container setAutoresizesSubviews:YES];
[meterInfoTableController.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight];

The code works in the sense that a UITableView with data is contained inside my container view, however the table is too big (you can see the last rows hiding outside the parent view when you pull it).

How do you properly resize the UITableView?

Edit: As per Mr_bem's answer I added the following:

[meterInfoTableController.view setFrame:CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height)];

Which worked fine :)

Upvotes: 0

Views: 397

Answers (1)

Albara
Albara

Reputation: 1296

You resize the UITableView by calling the setFrame method, and then pass a rectangle via CGRectMake

If you need more help, let me know :)

Upvotes: 1

Related Questions