Subclassing UITavlwViewController, loading from a Xib


#1

Hi there

I’m wondering if it’s possible in general to create a ViewController that is a subclass of UITableViewController but instead of having the UITableView take up the entire view, to load it from a xib… so when creating it you’d click “UITableViewController” and “use Xib for interface”.

I ask this because I’d like to do the following two items.

  1. more easily implement iAds. In the example for iAds, there is an IBOutlet pointing to a view in th viewController called “contentView”, and it seems like it would be simple to add a generic view on th UITableViewController XIB, and move the table onto that view co you have contentView–>tableView, and then hook up the IBOutlet for contentView to that newly added view.

That way the table would resize when I resize the view it lives on.

  1. Rather than subclassing UITableViewController, I’d like to actually subclass “PullRefreshViewController” [github.com/leah/PullToRefresh]

I’ve tried quite a few combinations of initialization strategies such as

  • creating a custom initializer which calls initWithStyle
  • not calling initWithStyle at all, but calling “- (void) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;”

The problem ends up being that the view always loads with the table taking up the full screen regardless of what I do in the Xib.

I’d like to avoid using a UIViewController on which I put a TableView and implement the two delegate protocols because I’d like to use the above “pulltorefresh” which itself is built on a UITableViewController…
I think I’m missing some basic thing here… anyone else tried to do this?


#2

Hi,

I don’t think you’ll be able to do this - I haven’t tried exactly what you’re describing but the UITableViewController wants to fill the screen.

From the apple docs

http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html

I guess you’ll have to reengineer the pullToRefresh code.

Gareth


#3

[quote=“GarethR”]Hi,

I don’t think you’ll be able to do this - I haven’t tried exactly what you’re describing but the UITableViewController wants to fill the screen.

From the apple docs

http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html

I guess you’ll have to reengineer the pullToRefresh code.

Gareth[/quote]

Hi Gareth

Thanks for the answer, and I think you’re right, now that I read that. Hmm. Well the good news is that I DID find what looks like a solution that might work on StackOverflow here-> stackoverflow.com/questions/6314 … n-a-uiview

Basically it’s just modifying the “PullRefreshTableViewController” to inherit from UIViewController, then manually put a UITableView on the view… add in the delegate protocol manually, and wire up an IBOutlet called tableView (UITableView).

That seems like it ought to work.