1

I have a tableView that navigates to a detail view when the user selects one of the tableView cells. This main TableView is created in a UITableViewController class. (MasterViewController)

I used StoryBoard to create the master-detail tableviews.

Within MasterViewController, I lay a tableView over top of the main tableView when the user selects the To button. This second tableView allows the user to select multiple values from this list.

In order to prevent this second tableView from scrolling on the screen when the first (main) tableView scrolls, I have added this second tableView to the superView of the MasterViewController view. ([self.view.superview addSubview:_toView];)

So, in MasterViewController, I add a TableViewController (_toController). I instantiate a UIView (_toView), add a background image to it (_toViewBG) and then add a TableView to it (_toTableView). I then add _toView (which contains this second tableView) to the superview of the MasterViewController view.

_toController = [[ToTableViewController alloc] init];
_toView = [[UIView alloc] initWithFrame:CGRectMake(10,10,263,247)];

_toViewBG = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,257,232)];
_toViewBG.image = [UIImage imageNamed:@"toViewBackground.png"];

[_toView addSubview:_toViewBG];

_toTableView = [[UITableView alloc] initWithFrame:CGRectMake(20,30,220,180) style:UITableViewStylePlain];

[_toTableView setDelegate:_toController];
[_toTableView setDataSource:_toController];
[_toView addSubview:_toTableView];

[self.view.superview addSubview:_toView];
[_toTableView reloadData];

This approach keeps the second tableView from scrolling when I scroll the main tableView. The second tableView stays on top and in place as the main tableView scrolls.

If I select a cell in the main TableView, I navigate to a detailed view. When I return to the main TableView, I am unable to get the second TableView (_toView) to be displayed.

I am not sure how to tell the _toView to come to the front. I realize it is added to the superview of the MasterViewController view. From some experimentation, this superview appears to be a CALayer.

Can anyone suggest how I would get this _toView to display in front of the MasterViewController view?

Thanks in advance for any assistance.

Solved I ended up just adding the second tableview as a subview of the MasterViewController view. [self.view addSubview:_toView]; I then disabled scrolling on the main tableview while my second tableview is visible.

Self.tableView.scrollEnabled  = No;

Seems to be working fine.

Tim

T Davey
  • 1,617
  • 1
  • 13
  • 14

1 Answers1

1

It may be possible to make this work by calling [self.view.superview bringSubviewToFront:_toView], but my advice would be to make MasterViewController a subclass of UIViewController rather than UITableViewController, and then add both of your UITableView objects as subviews of the root view, (rather than referring to superview).

ganzogo
  • 2,516
  • 24
  • 36
  • Thanks for the feedback. I had previously attempted your first suggestion without success. I was hoping to keep MasterViewController a UITableViewController as I create custom cell formats, add a UIRefreshControl to allow pull down refresh of the table view, etc. I assume it would be a fair amount of work to change to UIViewController. – T Davey Apr 17 '13 at 22:56
  • It shouldn't be that much work. You need to add a UITableView @property called tableView to your UIViewController, and init the property in your init method. Apart from that, everything should work as before. – ganzogo Apr 17 '13 at 22:59
  • Thanks. I'll give that a try and let you know if it works. Appreciate the help. – T Davey Apr 17 '13 at 23:03