Question

Below shows the default position when you add a grouped table to a view? How do I push the entire grouped table down in the view?

alt text
(source: pessoal.org)

Was it helpful?

Solution

You can assign a transparent view with a fixed height to the tableHeaderView property of the tableView. This will push the table contents down by the height of the transparent view.

You can do this from your UITableViewController's viewDidLoad:

// force the table down 70 pixels
CGRect headerFrame = self.tableView.bounds;
headerFrame.size.height = 70;

UIView *header = [[UIView alloc] initWithFrame: headerFrame];
header.backgroundColor = [UIColor clearColor];

self.tableView.tableViewHeader = header;

[header release];

OTHER TIPS

Look at the delagate to the UITableView.
You will find a property 'heightForHeaderInSection'.

For section 0 just make the header larger (default is 0) it will push the table down the view.

If you are moving the table down, you undoubtedly wish to use the space you gain to add UI elements.

At that point, consider building the page in IB. You can resize the table view to be where you like and put the UI elements above the table. You can use a UIViewController to manage the page and add the UITableViewDelegate/Datasource protocol methods so that you can wire the UITableView back to your view controller as a delegate... then you can also wire the other UI elements to the same view controller.

The simplest way to do it is probably just to modify the frame for the tableview. You'll need to get a reference to the tableview in your controller either through an IBOutlet or by finding the view in the view hierarchy OR you can change the frame in Interface Builder.

In code something like:

tableView.frame = CGRectMake(0.0, 200.0, 320.0, 280.0);

Would position the tableview down the screen and limit its height - the dimensions you use will be dependent on whether you had a tab bar on the view and things like that.

In interface build just select the tableview, then choose the Size inspector (the inspector tab with the ruler icon) and set the height and y offset to shift it down the view.

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