Since I read the objc.io post about light view controller, every few month I come back to the same problem: find the best way to write a table view controller.

seen from Italy
seen from Taiwan
seen from Indonesia
seen from Malaysia
seen from United States

seen from Malaysia
seen from United States

seen from Italy

seen from United States

seen from Indonesia

seen from Malaysia
seen from Germany

seen from Malaysia
seen from Indonesia

seen from Malaysia
seen from United Kingdom
seen from Malaysia

seen from Malaysia
seen from Serbia
seen from Indonesia
Since I read the objc.io post about light view controller, every few month I come back to the same problem: find the best way to write a table view controller.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Dynamic height for Cells inside a Table View.
Posts made by users appear in a TableView. A TableView arranges data in cells. Cells extend the full width of the screen are placed one after the other vertically. The user scrolls with a drag gesture to reveal more content in the cells above or below the current cell (usually cells) that is (are) being displayed currently on screen. In short, each Cloudshapes post is represented as cells in a Table View.
Among other data, a post consists of text that is of variable length. Depending on this length is the number of lines that the text spans. This number of lines is mainly what requires us to implement dynamic height.
In layman terms - More text = More lines = Taller UITableViewCell.
UITableViewControllers in iOS have two interesting delegate methods. tableView:cellForRowAtIndexPath:Â Â - lets call it cellFRAIP for short tableView:heightForRowAtIndexPath: - similarly we will call it heightFRAIP
For our purposes we can think of an Index path as just a numbering (index) of cells. So the first post that is displayed to the user is contained in a cell with indexPath 1, and so on.
By default in iOS all cells span the width of the screen. But the height of the cells may vary. To achieve this heightFRAIP is called first. This method returns a height value of type CGFloat. Once we have that we basically have the the dimensions of our UITableViewCell sub-class. Next cellFRAIP is called, this is where we create all the objects that go inside the cell.
Sounds, very straight forward right? WRONG !!!
It would have worked fine if my Fairy God Mother somehow told me how tall each cell was going to be. Since, she’s busy and we don’t have any data stored about the individual height, how do we go about this?
I don’t know whether there is a better way of doing this, but one way I discovered people were achieving this is by creating a Prototype Cell. We are not talking about a Storyboard Prototype Cell. It is just a property of our UITableViewCell sub-class which we declare in our custom UITableViewController sub-class. So now, when we call heightFRAIP we use this prototype cell, layout some of the things in it and record the vertical heights of these things laid out. Adding up all the heights gives us the height of the cell which we pass back.
cellFRAIP then uses this height, creates a cell, and returns that cell so that it can be drawn on screen.
There are more details to this, but is beyond the scope of this article. The reader should refer to iOS documentation for more information about the functions that are mentioned here.
How to: UITableView backgroundColor always gray on iPad
How to: UITableView backgroundColor always gray on iPad
UITableView backgroundColor always gray on iPad
When I set the backgroundColor for my UITableView it works fine on iPhone (device and simulator) but NOT on the iPad simulator. Instead I get a light gray background for any color I set including groupTableViewBackgroundColor.
Steps to reproduce:
Create a new navigation-based project.
Open RootViewController.xib and set the table view style to…
View On WordPress
Remove UITableView Extra Padding on Top
This is what I did to remove the extra padding on top of my UITableView inside my UITableViewController
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
UITableView
A UITableView shows a single column of data, with 1 or more rows:
A UITableView is best accompanied by a UIViewController to handle its appearance on the screen.
A UITableView takes a data source, conforming to UITableViewDataSource, from which to display data.
A UITableView takes a delegate, conforming to UITableViewDelegate, to inform it of events involving itself.
An associated UITableViewController normally acts as view controller, data source, and delegate.
UITableViewController has a view, which is an instance of UITableView. When a UITableViewController creates its view, the dataSource and delegate variables of the UITableView are automatically set to point to the UITableViewController.
The designated initializer of UITableViewController is initWithStyle:, which can be either UITableViewStylePlain or UITableViewStyleGrouped (where the top and bottom rows have rounded corners).
loadView on UITableViewController creates and loads an empty UITableView if none exists.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Sizing a UIPopoverController to fit a UITableViewController
A common UIPopoverController use case is to use it to display a UITableViewController. When doing so, you'll likely want the popover to be as tall as the table view's content size requires. It wasn't immediately obvious to me how to achieve this, but adding the following code in the content view controller's viewDidLoad method appears to do the trick:
CGFloat height = CGRectGetMaxY([self.tableView rectForSection: [self.tableView numberOfSections] - 1]) self.contentSizeForViewInPopover = CGSizeMake(320, height);
It's worth noting that this doesn't work in either viewWillAppear: or viewDidAppear:.
Disallow selection in TableView after popViewController
A very common scenario is to use TableViewControllers in a UINavigationController push/pop stack. When a UITableViewController is an intermediate view controller i.e. tapping on its cells brings you to another view controller, you might also want to return back to it. The default behavior is this case is to select the cell you tapped on last, which is not necessarily the desired behavior for your app.
In order to deselect this cell, the following code snippet will help:
- (void)viewWillAppear:(BOOL)animated {
  NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
  if (indexPath) {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  }  Â
}