我试图搜索这个站点和整个互联网,但我还没有找到一种方法可以让我在多个视图控制器之间切换同时在它们之间共享数据。我尝试使用以下代码(第一个方法调用另一个方法然后切换视图):
-(IBAction) choosePhoto:(id)sender {
[self startMediaBrowserFromViewController: self
usingDelegate: self];
if(firstViewController.view.superview == nil)
{
[secondViewController viewWillAppear:YES];
[firstViewController viewWillDisappear:YES];
[firstViewController.view removeFromSuperview];
[self.view insertSubview:self.secondViewController.view atIndex:0];
[firstViewController viewDidDisappear:YES];
[secondViewController viewDidAppear:YES];
}
//3. now add animation
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//blue view will appear by flipping from right
if (secondViewController.view.superview == nil)
{
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[secondViewController viewWillAppear:YES];
[firstViewController viewWillDisappear:YES];
[firstViewController.view removeFromSuperview];
[self.view insertSubview:self.secondViewController.view atIndex:0];
[firstViewController viewDidDisappear:YES];
[secondViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
- (IBAction)switchViews:(id)sender {
if(self.secondViewController.view.superview == nil)
{
[firstViewController.view removeFromSuperview];
[self.view insertSubview:secondViewController.view atIndex:0];
}
}
这做了一个很好的动画,但不会切换视图控制器。
请帮忙?
编辑:还将另一个视图放在第一个视图控制器中以及如何切换视图会有所帮助。