lmirosevic
lmirosevic

Reputation: 16317

How to set size of UITableView inside Interface Builder?

Is it possible to change the frame of UITableViewController's UITableView frame inside Interface Builder? I want to make my table, which I instantiate in IB, a little bit narrower.

Upvotes: 1

Views: 2732

Answers (2)

smparkes
smparkes

Reputation: 14063

You can change it in IB but unless you customize your view controller somehow, it will set it be full screen (module enclosing controllers like nav, tab bar, split view, etc.) That's just the way view controllers work.

From the Apple docs:

When a view controller is displayed on screen, its root view is typically resized to fit the available space, which can vary depending on the window’s current orientation and the presence of other interface elements such as the status bar.

You can create another UIView to hold your table view and then have more control over the table view sizing, But then you won't be a table view controller and will have to implement some of the things that table view controller provides you, e.g., deselectRowAtIndexPath on viewDidAppear.

Upvotes: 1

George Green
George Green

Reputation: 4905

When you have create your tableViewController in IB, if you then go to the section on the right of the screen where all the options are set size to "freeform" then drag it to whatever you like. When you init it it will then get this frame. Unless it is within a container controller.

The best way to do what you are after is to create a viewController and add a table view to its view. Make the table view narrower that the main controller view and wire it up to an IBOutlet on your controller. If you then make your controller implement the and methods you will be able to use your table view exactly as you want to.

Hope this is of help to you, if this is unclear or you would like any extra help, let me know :)

Upvotes: 2

Related Questions