[英]Sending data from one uiviewcontroller to another navigationcontroller using present modally
[英]NavigationController: Replacing a pushed UIViewController with another one
为了更好地理解以下问题,以下是一张小图,说明了我的应用程序的结构: http : //grab.by/6jXh
因此,基本上,我有一个基于导航的应用程序,该应用程序使用NavigationController的“ pushViewController”方法显示视图A和B。
我想要完成的是从视图A过渡到视图B,反之亦然。 例如,用户按下主视图中的“ A”按钮,使用NavigationController推入视图A。 在此视图中,用户可以按下按钮“ Flip to B”,并且View B替换NavigationController堆栈上的View A(在视觉上,这是使用Flip过渡完成的)。 如果用户按下视图B上的“后退”按钮,则会再次显示主视图。 为了节省使用的内存,必须取消分配/卸载/删除当前未显示的View(Controller)。
什么是合适的方法? 我需要某种ContainerViewController还是可以做到?
谢谢。
您可以创建一个ContainerViewController类,然后按以下方式进行推送:
ContainerViewController *containerViewController = [[ContainerViewController alloc] initWithFrontView: YES];
[self.navigationController pushViewController: containerViewController animated: YES];
[containerViewController release];
该类可能看起来像这样:(因为您可以将其正面或背面视图置于顶部)
- (id)initWithFrontView: (BOOL) frontViewVisible {
if (self = [super init]) {
frontViewIsVisible = frontViewVisible;
viewA = [[UIView alloc] init];
viewB = [[UIView alloc] init];
if (frontViewIsVisible) {
[self.view addSubview: viewA];
}
else {
[self.view addSubview: viewB];
}
//add a button that responds to @selector(flipCurrentView:)
}
return self;
}
- (void) flipCurrentView: (id) sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
if (frontViewIsVisible == YES) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: self.view cache:YES];
[viewA removeFromSuperview];
[self.view addSubview: viewB];
} else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView: self.view cache:YES];
[viewB removeFromSuperview];
[self.view addSubview: viewA];
}
[UIView commitAnimations];
frontViewIsVisible =! frontViewIsVisible;
}
并且不要忘了照顾内存管理。 我还建议您看一下http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html-几乎正是您所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.