我是iOS的初学者。在我的ParentViewController中,我添加了一个ChildViewController。在该控制器中,我添加了一个Next按钮。当我点击那个按钮时,我正在将First ChildViewController推向Second ChildViewController。这很好。
但在这里我在第二个ChildViewController中添加了另一个按钮。当我点击那个按钮时,我想从Second ChildViewController返回到First ChildViewController。但我的代码不能正常工作。请帮帮我
我的代码:
ParentViewController:
#import "ParentViewController.h"
@interface ParentViewController ()
@end
@implementation ParentViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
ChildViewController1 *ViewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController1"];
ViewController1.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
ViewController1.view.backgroundColor = [UIColor cyanColor];
[ViewController1 willMoveToParentViewController:self];
[self.view ViewController1.view];
[self ViewController1];
}
@endChildViewController1:
#import "ChildViewController1.h"
@interface ChildViewController1 ()
{
}
@end
@implementation ChildViewController1
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)next:(id)sender{
ChildViewController2 *middleVC =[self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController2"];
middleVC.view.hidden=FALSE;
[middleVC.view setFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self addChildViewController:middleVC];
[self.view addSubview:middleVC.view];
[middleVC didMoveToParentViewController:self];
[UIView animateWithDuration:0.5 animations:^{
[middleVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}ChildViewController2:
#import "ChildViewController2.h"
@interface ChildViewController2 ()
{
}
@end
@implementation ChildViewController2
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)back:(id)sender {
ChildViewController2 *middleVC =[self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController2"];
middleVC.view.hidden=FALSE;
[middleVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self addChildViewController:middleVC];
[self.view addSubview:middleVC.view];
[middleVC didMoveToParentViewController:self];
[UIView animateWithDuration:0.5 animations:^{
[middleVC.view setFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}在这里,当我点击后退按钮时,它不会向后推。
发布于 2015-11-25 21:55:06
在ChildViewController2后退按钮操作中,您拥有:
ChildViewController2 *middleVC =[self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController2"];你的意思不是:
ChildViewController1 *middleVC =[self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController1"];https://stackoverflow.com/questions/33918061
复制相似问题