質問

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

役に立ちましたか?

解決

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

If you need more help, let me know :)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top