Question

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 :)

Was it helpful?

Solution

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

If you need more help, let me know :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top