0

I have add Facebook like menu in my app. For that i have create two ViewController. On menu button click add LeftViewController as childViewController .its working fine as shown in image. here is my code:-

[self addChildViewController:left];

[self showMenu];

[view_mainHome addSubview:left.view];

[left didMoveToParentViewController:self];

Now i call a function of ParentViewController to close this view from childViewController i.e (LeftViewController). So the problem is method is called but view not animate.I am calling method like :- ParentViewController * parent = [[ParentViewController alloc]init]; [parent hideLeftMenu];

My method in ParentViewController.m like:-

-(void)hideLeftMenu{

LeftMenuViewController *left=[[LeftMenuViewController alloc]init];
[left removeFromParentViewController];
//slide the content view to the left to hide the menu
[UIView animateWithDuration:.5 animations:^{
    self.navigationController.navigationBar.frame = CGRectMake(0, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);

    [view_Home setFrame:CGRectMake(0, view_Home.frame.origin.y, view_Home.frame.size.width, view_Home.frame.size.height)];

}completion:^(BOOL finished)
 {
     for(UIView *view in [view_mainHome subviews]){
         [view removeFromSuperview];
     }
 }];

}

view Image

Guri
  • 85
  • 1
  • 1
  • 9
  • Maybe you can animated it before removing from superview. http://stackoverflow.com/questions/10700933/how-to-animate-removefromsuperview – Maurice Jun 26 '14 at 11:43
  • No i am not removing view of parentViewController. Nothing happen when i click on notification, just method called and even app not crash. – Guri Jun 26 '14 at 11:52

1 Answers1

0

Any time you are calling a VC by using alloc init, it is generating a new copy of that object, not targeting the one you already have. If you want to call a function on the parent VC you will can use the notification center to send a message to it, or you can store a reference to it. Then just make sure you are NOT using "alloc init" when targeting an existing object, as that will not effect the visible views.

box86rowh
  • 3,415
  • 2
  • 26
  • 37