tranvutuan
tranvutuan

Reputation: 6109

how to resize the width of table view controller

My class is UITableViewController. How can I decrease a width of a cell of my table view or decrease the width of my table view.

Please advice me on this issue.

Upvotes: 1

Views: 2319

Answers (4)

bhavya kothari
bhavya kothari

Reputation: 7474

You can re-size UITableViewController as if you are re-sizing any images in word. Sometimes it becomes difficult to select UITableViewController.

If using .xib or nib file.

Steps :
1.Select your nib file.
2.Expand vertical bar bearing (file's owner & first responder) called dock.
3.Select appropriate table view controller.
4.Now you can easily re-size a particular controller.

If using StoryBoard

Steps:
1.Select your MainStoryboard.StoryBoard file.
2.Click on expand button besides Project Navigator.
3.Select appropriate table view controller.
4.Now you can easily re-size a particular controller.

OR

You can re-size it programmatically by CGRectMake(x,y,width,height) Refer Apple Documentation for further variations.

Upvotes: 2

rooster117
rooster117

Reputation: 5552

You can just manually resize the frame.

Assuming the tableview is just within a view controller.

CGFloat newWidth = [your new value];

yourTableViewController.view.frame = CGRectMake(yourTableViewController.view.frame.origin.x,  yourTableViewController.view.frame.origin.y, newWidth, yourTableViewController.view.frame.size.height);

You may need to give more info on exactly what you need but this might be enough to get you going.

Upvotes: 1

danh
danh

Reputation: 62686

Consider making the UITableViewController into a simple UIViewController with a table view subview. That table can be framed any way you like. Declare the plain view controller as and connect those outlets in IB.

There are one or two more behaviors (e.g. table view controller deselects the currently selected row on viewWillAppear) that the UITableViewController supplies, but there's not really much to it.

In my opinion, for what it adds, the UITableViewController comes with this layout penalty you're seeing, often making it a poor trade. Whenever I need even a layout tweak, I delete it in favor of the vanilla vc without any remorse.

Upvotes: 0

Garoal
Garoal

Reputation: 2374

To decretase the width of the table view:

self.tableView.frame = CGRectMake(x, y, width, height);

I think you cannot change the width of an UITableViewCell, it will be always the same that the tableView

Upvotes: 1

Related Questions