On Aug 3, 2011, at 3:49 PM, Jens Alfke wrote: > I’ve got an iOS screen that incorporates a UITableView. This screen is run by > a UIViewController subclass. I’d like to subclass UITableViewController > instead, to get more table behaviors for free. The problem I’m running into > is that the table view is not the root view of my nib. (There’s a text field > above the table that’s a sibling of it.) > > As far as I can tell, UITableViewController only works when the table is the > root of the nib. It does have a separate ‘tableView’ property, but this isn’t > an IBOutlet so there’s no way to wire it up to the table view in the nib. > Instead, the class assumes that the ‘view’ outlet — which must point to the > nib’s root view — is the table view, and raises an assertion failure > otherwise. > > I’m trying to figure out a way around this, but every workaround I think of > makes the project more complicated, canceling out the benefit of switching to > UITableViewController. Is there a clean way of doing it that I’m missing? >
UITableViewController, like all UIViewControllers, expect their view to be the "root" of the window (where "root" is defined as either being the only subview of the UIWindow) or the current/topmost view controller of a UINavigationController, UITabViewController, UISplitViewController, etc... UIViewControllers are not designed to have their views inside other arbitrary views (except for the previously mentioned UINavigationController, etc...). For more detail, there was a WWDC session on "Implementing UIViewController Containment". To add a text field (or other arbitrary views) "along side" the table view, you have a couple of choices: - Put it in the table view header view. Disadvantage is that it can get scrolled off screen - Put the view in a row in its own section. Similar to previous - Put it in the first section's header view. Only works well if you have a single section, are in non-grouped mode - Put the view into the navigation controller's title view. Limits the height of your view, and assumes you've got a nav controller, and aren't already using the title You can also play games where you add the view to the tableview itself, and, since the tableview is a scrollview, adjust the content to allow that item to show, and then, upon scrolling, make sure the view is on the top of the screen (both in Y and Z coordinates, since the table view may have made a new cell that ends up layered covering your view) Glenn Andreas [email protected] The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
