Using a UITableViewController with a small-sized table?
Posted
by rpj
on Stack Overflow
See other posts from Stack Overflow
or by rpj
Published on 2008-10-21T18:33:21Z
Indexed on
2010/03/09
2:06 UTC
Read the original article
Hit count: 326
When using a UITableViewController, the initWithStyle: method automatically creates the underlying UITableView with - according to the documentation - "the correct dimensions".
My problem is that these "correct dimensions" seem 320x460 (the iPhone's screen size), but I'm pushing this TableView/Controller pair into a UINavigationController which is itself contained in a UIView, which itself is about half the height of the screen.
No frame or bounds wrangling I can come up with seems to correctly reset the table's size, and as such it's "too long", meaning there are a collection of rows that are pushed off the bottom of the screen and are not visible nor reachable by scrolling.
So my question comes down to: what is the proper way to tell a UITableViewController to resize its component UITableView to a specified rectangle?
Thanks!
Update I've tried all the techniques suggested here to no avail, but I did find one interesting thing: if I eschew the UINavigationController altogether (which I'm not yet willing to do for production, but as an experiment), and add the table view as a direct subview of the enclosing view I mentioned, the frame size given is respected. The very moment I re-introduce the UINavigationController into the mix, no matter if it is added as a subview before or after the table view, and no matter if alloc/init it before or after the table view is added as a subview, the result is the same as it was before.
I'm beginning to suspect UINavigationController isn't much of a team player...
Update 2 The suggestion to check frame size after the table view on screen was a good one: turns out that the navigation controller is in fact resizing it some time in between load and display. My solution, hacky at best, has been to cache the frame given on load and to reset it if changed at the beginning of tableView:cellForRowAtIndexPath:. Why there you ask? Because it's the one place I found that worked, that's why!
I don't consider this a solution as it's obviously improper, but for the benefit of anyone else reading, it does seem to work.
© Stack Overflow or respective owner