woutr_be
woutr_be

Reputation: 9732

Set the height of a UITableView

For some reason it's not possible for me to adjust the height of a UITableView from within my controller, in my viewDidLoad I did this:

[self.tableView setBounds:CGRectMake(0.0f, 0.0f, 320.0f, 100.0f)];
[self.tableView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 100.0f)];

self.tableView.bounds = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);
self.tableView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);

I just tried every option, but nothing seems to change the height of my table.

Upvotes: 0

Views: 694

Answers (2)

MGA
MGA

Reputation: 3751

Use a UIViewController, and add UITableViewController as a child view controller. Then you can add the UITableViewController's view as a subview to your UIViewController and set the frame as you wish. You can use the UIViewController to control the rest of the UI elements and the UITableViewController to control the table.

Note that this method uses UIViewController containers which is an iOS 5 feature.

Upvotes: 0

lnafziger
lnafziger

Reputation: 25740

UITableViewController will automatically make the tableview full screen.

Taken from the View Controller Programming Guide:

Note: You should use a UIViewController subclass rather than a subclass of UITableViewController to manage a table view if the view to be managed is composed of multiple subviews, one of which is a table view. The default behavior of the UITableViewController class is to make the table view fill the screen between the navigation bar and the tab bar (if either are present).

Upvotes: 2

Related Questions