views:

327

answers:

1

I'm trying to add a UIView, in particular a UIImageVIew, after (that is, below, but not in a z-index sense) a UITableView but before (that is, above) a UITabBar.

You know, the typical "banner/adv space" that you can see everywhere.

My main problem btw is that i don't know exactly where to put it, as a subview of wich view specifically; the UITableView resize automatically according to the space left from the UITabBarController's main view height, minus the height of the tabbar. I would like it to be put inside the UITableView instead of somewhere else beacuse it is more related to the content of the UITableView, but i have all the autoresizing problems of above. I've tried playing with autoresizingmask, and with the autoresizesubviews flag, but without success. I've even tried the footer ot the UITableView, but that is not fixed in position, it scrolls away if the table is long (expected, and normal).

Is there a way to add a subview in that point, stretching the table itself correctly?

Thanks everybody.

+1  A: 

Use a normal UIViewController instead of a UITableViewController. Use the view controller's view as a container view in which you place the table view and the image view. Your view controller can still act as your table view's delegate and/or datasource.

Ole Begemann
@ole: i was trying to do that just before posting, but inside the UITableViewController subclass i was creating, i was able to set the tabbar item, the title and so on while with the UIViewController sublcass i can't chan... oh wait. I'm an idiot. I was subclassing UIVIew instead of UIViewController. Ok, probably after 48 hours of non-stop coding i need some sleep time.Thanks Ole, i'll now try to see if that works and accept your answer!
njy
@ole: ok, i've created a TableViewControllerWithAd class (:UIViewController) and inside its "init" i have created a MyTableViewController instance (:UITableViewController) and addSubView'd it to the self.view main view. After that, Then i've changed the "loadDidView" of the RootController to use that. Now, the "thing" is showing up, but it's interaction is messed up: i can click the rows, but i can drag (scroll) them only as if the height of the thing is the height of the containing view, and not the underneath tableview. And some strange row separators are showing up over the underneath rows.
njy
You're thinking to complicated. There is no need for MyTableViewController at all. Just create a UITableView and add it to your view controller's view (either in IB or in `loadView`). And assign your view controller as the table view's delegate and datasource.
Ole Begemann
@ole: oooh, wonderful! I was so stupid i didn't get it before: a UITableViewController is just a UIViewController, declared to respect the UITableViewDelegate and the UITableViewDataSource protocols, with the initialization of the UITableView inside it's init, and with the additional "tableView" property already mapped to it's view, to avoid casting it everytime you need it for table-specific purposes. Now it seems to work as expected, and everything makes more sense. Thanks!p.s.: btw, is what i just wrote correct or am i missing something?
njy
@ole: i'll add that another difference is that in my case the UITableView will be the first subview of the controller's view, whereas in the UITableViewController case, it will directly be *the* controller's view itself, without an additional hierarchycal level.
njy
Yes, you're basically correct. Have a look at UITableViewController.h. It's a very small file so you can see the class doesn't do much. The file contains very good comment on what exactly UITableViewController does.
Ole Begemann
@everybody: just like to warn about a little caveat: if you do as said above, sometimes (everytimes?) it may happen that strange things happen visually, like rows separators over your table view and so on. In these cases i've just rewritten the "loadView" method, creating by myself the main view of the UIViewController subclass you're creating, and then adding everything else inside it. In this way no problem occur.
njy