gpt4 book ai didi

iphone - 将 ViewController 添加为 subview 并显示发送到已释放实例 0x8a6efc0 的消息

转载 作者:行者123 更新时间:2023-11-29 13:11:52 25 4
gpt4 key购买 nike

我有 ViewControllerUIButton

- (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 的 subview 。

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){
}];
}

问题当我按下 MenuViewController 上的按钮时,它会将新的 FirstViewController 呈现为带有动画的 subview ,但是当我按下 FirstViewController 上的按钮时,它会崩溃

-[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x8a6efc0 

请检查。

最佳答案

FirstTopViewController *controller 作为类级变量。问题是 Controller 对象是本地的,并且在 btn_funtion 完成后被释放。然后,当您点击按钮时,它会将消息发送到已释放的实例。

关于iphone - 将 ViewController 添加为 subview 并显示发送到已释放实例 0x8a6efc0 的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com