Send subview to back
Asked Answered
P

2

11

I'm trying to mimic the facebook ios side menu and have it working however the issue I am having is that I cannot send the sidemenu to the back as discussed in another question on SO iphone facebook side menu using objective c. I'm not using the library suggested but instead using the code that was suggested. I have

- (void)viewDidLoad
{
    NSLog(@"View Did Load is running");
    activitySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activitySpinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    activitySpinner.center = self.view.center;
    [self.view addSubview:activitySpinner];

    SideMenuView *myDelegate = [[SideMenuView alloc] init];
    [self setSideMenuDelegate:myDelegate];
    //set the delegate's currentViewController property so that we can add a subview to this View. 
    [sideMenuDelegate setCurrentViewController:self];

    //sideMenu = [[SideMenuView alloc] initWithNibName:@"SideMenuView" bundle:nil];
    [self.view addSubview:myDelegate.view];
    [self.view sendSubviewToBack:myDelegate.view];

    [super viewDidLoad];
    self.searchDisplayController.searchBar.scopeButtonTitles = nil;

    [self fetchCustomers];
    // Do any additional setup after loading the view, typically from a nib.
}

In my controller where I want the side menu but the view seems to get loaded into the current view instead of just going to the back so it can be seen when I slide the menu over.

Can someone help me get the myDelegate view to the back?

Pippa answered 18/1, 2012 at 16:55 Comment(0)
U
32

I am not entirely sure what you are trying to accomplish, so I have to guess. It sounds like you want to hide myDelegate.view behind self.view. It won't work this way.

sendSubviewToBack: sends the subview to the back of the view hierarchy of the sender, in your case, self.view. It will never send a subview below its superview.

You can instead add myDelegate.view as a subview to self.views superview, and put it behind self.view:

[[self.view superview] insertSubview:myDelegate.view belowSubview:self.view];
Unrepair answered 18/1, 2012 at 17:5 Comment(8)
Your code removes it from the list however it still doesn't show it in the background when I slide the menu over. I'm editing my OP to include the suggestion I followed for the slide menu.Pippa
I see what you're trying to accomplish, but you don't give enough details - I can't see your whole view hierarchy, and I can't guess which view does what and what frames they have. To be honest I don't even really know what you mean by "showing in the background" anymore.Unrepair
did you read the link in the OP? That guy explains what to do but I just can't seem to get it to work.Pippa
I know what it's supposed to look like, I just don't know what your problem is: Does it not display at all, does it display on top of something it shouldn't be on top of? Also, I have no idea what your self.view contains, or where your ordinary content view (the one that slides out to the side) is.Unrepair
My self.view is a tableview container with items. When I click the slide button it slides but the left menu is all black like it wasn't loaded. The left view will be a table view as well.Pippa
So your self.view is the view that people see when the menu isn't shown? And myDelegate.view is the menu? And what is this "left" view? This is the first time you mention this.Unrepair
yes that is correct sorry the left view is the myDelegate. it shows on the left so i referred to it as left view.Pippa
Then my original answer is still correct. As to why it doesn't show then, I don't know. I'd need to see a bit more of your code to tell you what's going wrong, but that would feel like doing your work for you. Have a good night! :)Unrepair
P
0

I've decided to just go with https://github.com/Inferis/ViewDeck and let that manage the views.

Pippa answered 20/1, 2012 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.