I am using a UITableViewController, I have resized the height of the table view and moved it a little down. Now I'd like to add a UIImageView above that table view but the only thing that I can do is add that UIImageView as a subview of the UITtableView of the UITableViewController, so that UIImageView is not above the UITableView and the image scrolls with the table view.
How can I accomplish what I'm trying ? Here is the code I've been using :
UIImageView *tabImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"temp.png"]];
[self.view addSubview:tabImageView];
Thanks!
I believe UITableViewController
requires that its view
be a UITableView
.
In the past, I've worked around this by changing my view controller from subclassing UITableViewController
to subclassing UIViewController
and implementing the UITableViewDataSource
and UITableViewDelegate
protocols. Then you can have your view
be whatever you want, including shifting your UITableView
down and adding a UIImageView
.
Not sure if this is still the case in 4.2, though.
Just want to clarify that this is really not a great idea for many reasons, a bunch of which are listed in the comments. You should really be doing what Shaggy Frog is suggesting, or using View Controller Containment.
You want the UIImageView
to be static at the top of the tableView
? If that's so, you need to set it as a subview of the UINavigationController
, not the UITableView
. Easiest way to do this is with [self.view.superview addSubview:tabImageView]
. (although as Shaggy Frog said, it's probably best to change from a UITableViewController
to a plain UIViewController
, and create the UITableView
manually)
If you want the UIImageView
to be attached to the UITableView
, so that when you scroll down, it disappears, you can just set it as the table header with [self.tableView setTableHeaderView:tabImageView]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With