views:

1590

answers:

3

I have a UITableViewController inside of a UINavigationController.

I want to have a UIView appear over the top of the table view but not susceptible to the scrolling of the table view.

I.e. if the table view is scrolled, the UIView should remain in the same position relative to the screen, rather than relative to the table view. It should appear anchored in a certain position.

What is the best way to achieve this?

EDIT: To clarify, the view should float transparently over the top of the table view.

Many thanks!

A: 

Do you mean the anchored view should appear transparent over the UITableView, or just above, i.e. anchored view uses top 20% of the available space, table view uses the rest?

In any case, create a UIView containing the anchored view and the table view. If you want the anchored view transparent over the table view, it's a bit tricky, because to scroll the table view, touches have to pass through the anchored view.

Add the surrounding view's view controller to the navigation controller instead of just the tableview.

rincewind
Thanks but I meant that the anchored view should float above the table view.
A: 

Similar to what Peter said, create a UIView that will contain both the TableView and the subclassed UIView. Such as:

UIView *view = [[UIView alloc] initWithFrame:frame]; // Define frame as you like

[view addSubview:myTableView]; // This is the reference to your tableView
[view addSubview:myAnchoredView]; // This is the reference to your UIView "floating" subclass

You will also need to turn off user interaction for your floating view. I don't know if this will specifically pass the touches to the underlying UIView's or not though:

[myAnchoredView setUserInteractionEnabled:NO];

If this is blocking touches to your tableView, you may need to pass the reference to your tableView to the anchored view at initialization, then pass the touch events along. You can do this by overriding the touch response methods in UIResponder. (If there is a better way, someone please speak up.)

craig
A: 

I also wanted to have a floating UIView over my tableView.
So, within my RootViewController (which is a UITableViewController), this worked for me

- (void)viewDidLoad {
    /* mylabel is a UILabel set in this class */
    [self.mylabel setUserInteractionEnabled:NO];

    /* navigationController comes from higher up in the navigation chain */
    [self.navigationController.view addSubview:self.mylabel]; 
 }
ojreadmore