Reputation: 4636
I am trying to implement a custom UIActionSheet(made up of a ViewController) I have added a View Controller as a subView to the navigationcontroller of my rootView
- (IBAction)ShowMenu:(id)sender
{
[self.navigationController.view addSubview:self.menuViewController.view];
[self.menuViewController setTest:YES];
[self.menuViewController viewWillAppear:YES];
}
here MenuViewController has a tableview which has few options to select. After selecting I am opening those respective ViewControllers. Suppose I clicked on menu1 and then opened menu1ViewController and it works fine. Now when I close this viewController, I am calling dismissViewController.
and in menuViewController I have written the code to animate by menuviewController to bottom and it works fine.
but the parent of MenuView is TestViewController inside which the functions viewdidAppear is not called when menuviewController animates down.
and thats my problem,
I am using this code to animate by menuViewController to bottom
- (void) slideOut {
[UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];
// Set delegate and selector to remove from superview when animation completes
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
// Move this view to bottom of superview
CGRect frame = self.menusheet.frame;
frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
self.menusheet.frame = frame;
[UIView commitAnimations];
}
// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
[self.view removeFromSuperview];
}
}
MenuViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(m_test)
{
[self slideIn];
m_test = FALSE;
}
else
{
[self slideOut];
}
}
Upvotes: 0
Views: 1318
Reputation: 3184
IMHO, -[UIViewController viewWillAppear]
and -[UIViewController viewDidAppear]
would only be called where the callee is added into the view controllers hierarchy by those container-like controllers, like a navigation controller, a tab bar controller.
It would not be called if you just add the view by calling addSubview:
in your code. See also.
You could call -viewWillAppear
and -viewDidAppear
where appropriate, programmatically in your code, before and after you called addSubview:
with or without animations.
Upvotes: 3