Reputation: 6349
I have a UINavigationController and UITableView in my MainWindow.xib. I'm trying to insert a non-touchable/non-movable image at the top of the view. (I don't want to simply change the UINavigationBar background, as from what I've experienced, the UINavigationBar height cannot be arbitrarily increased.)
As this is a root view, its behaviour is controlled by my RootViewController. When the view loads, I hide the navigation bar using self.navigationController.navigationBarHidden = YES;
I've tried adding a UIView to the top of the UITableView, but when the user scrolls through the table, the top image moves. How can I place a stationary image at the top of the UITableView without it moving as if it were a cell and without using a UINavigationBar background image?
Naively-Considered Possibilities:
(HIG violation, anyone?)
Upvotes: 2
Views: 1334
Reputation: 3422
You can create another UIViewController
which contains the UITableViewController
and your static image on top. This way, you can even resize the table view so the static image is displayed above and not over your table.
UIViewController *middleViewController = [[UIViewController alloc] init];
[[middleViewController view] addSubview:tableView];
[[middleViewController view] addSubview:staticImageView];
...
[navigationController initWithRootViewController:middleViewController];
Has been a long time since I made my last cocoa application, so I cannot promise that it works.
Upvotes: 1
Reputation: 54151
If your view controller is a UITableViewController
you can't easily add another view because the tableViewController just manages a single view which is the UITableView
. I recommend using a plain UIViewController
instead where you add a UIView
for your top view and a UITableView
for your content as subviews to the main viewController.view
. Then, implement the UITableViewDelegate
and UITableViewDataSource
protocols in your UIViewController
.
Upvotes: 1