The task I’m currently trying to do with UITableViewController is to have one-column-cell-row in portrait mode, and two-column-cell-row in landscape mode. It’s just for the viewing convenience (using available width space for viewing more rows-cells), so both column cells are of the same format. However, I’m not sure how to implement that.
So, the thought is to have my cell customization stuff in “cellForRowAtIndexPath” method and to check for the current screen mode. The question is do I have to set some flag at “shouldAutorotateToInterfaceOrientation” or there is some setting for that?
Second, would it be enough to call just table reload in “shouldAutorotateToInterfaceOrientation” in order to redraw cells of my table?
Also, I’m thinking about making different nib and designing my cell in IB. I guess it’s another question, just wondering how does that would affect the solution.
You have to check the current orientation in
cellForRowAtIndexPathand configure your cell properly. You can create 2 different cells with IB.Also, you have to call
[myTableView reloadData]in one of the callbacks for rotation events (shouldAutorotateToInterfaceOrientationordidRotateFromInterfaceOrientation).cellForRowAtIndexPathwill be called each time you call[myTableView reloadData](for all cells).Be sure you use different identifiers for reusing cells.
EDIT: This is how I would code this:
Add 2 IBOutlets to your .h file:
In Interface Builder, set the identifier property of each cell, maybe something like
cellIdentifier1andcellIdentifier2. Be sure that the file’s owner in IB is your dataSource (the place wherecellForRowAtIndexPathis implemented).cellForRowAtIndexPathshould look like this:}