我ViewController
与UIButton
- (IBAction)buttonPressed:(id)sender {
FirstTopViewController *controller = [[FirstTopViewController alloc]init];
controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Upper"];
controller.view.frame = CGRectMake(300,0, 320, 460);
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
controller.view.frame = CGRectMake(20, 0, 320, 460);
}
completion:^(BOOL finished){
}];
[self.view addSubview:controller.view];
}
在这里,我将newViewController添加为MenuViewController
的子视图。
使用FirstViewController
UIButton
上
- (IBAction)backToMain:(id)sender {
[UIView animateWithDuration:1.5
delay:0.5
options: UIViewAnimationCurveEaseIn
animations:^{
self.view.frame = CGRectMake(0, 490, 320, 460);
}
completion:^(BOOL finished){
}];
}
ISSUE
当我按下MenuViewController
上的按钮时,它将新FirstViewController
显示为带有动画的subView,但是当我在FirstViewController
上按下按钮时,它会崩溃
-[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x8a6efc0
请查看。
答案 0 :(得分:1)
将FirstTopViewController *controller
作为类级别变量。问题是控制器对象是本地的,并在btn_funtion完成后被解除分配。然后,当您点击按钮时,它会向已解除分配的实例发送消息。
答案 1 :(得分:0)
在MenuViewController的.h文件中创建一个FirstViewController实例。 现在,您的FirstViewController实例将由父视图保存。