Ios错误:@auto发布池“EXC_BAD_ACCESS”下的线程1 [英] Ios error: Thread 1 under @auto release pool "EXC_BAD_ACCESS

查看:257
本文介绍了Ios错误:@auto发布池“EXC_BAD_ACCESS”下的线程1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用崩溃,当我点击后退按钮时显示此错误。我有2个视图控制器。在第一个vc的开始按钮工作正常切换到第二个视图,但当我点击后退按钮应用程序崩溃,我得到上面的错误@autorelease池下面的行。我也将发布代码为我的开始&后退按钮。 thx :)
#import
#importAppDelegate.h

The app crashes and shows this error when I hit the Back button. I have 2 view controllers. On the first vc the Start button works fine to switch to second view, but when I hit the Back button the app crashes and I get the error above on the line below @autorelease pool. I will also post the code for my start & back buttons. thx :) #import #import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate      class]));
}
}

第一个vc.H文件开始按钮到第二个视图)

First vc.H file Start Button (this works switching to second view)

 @interface ViewController : UIViewController  
{
IBOutlet UIButton *StartQuiz;
IBOutlet UIButton *HowToPlay;
IBOutlet UIButton *Credits;
IBOutlet UIButton *Back;
IBOutlet UILabel *Label;
}

-(IBAction)StartQuiz:(id)sender;
-(IBAction)HowToPlay:(id)sender;
-(IBAction)Credits:(id)sender;
-(IBAction)Back:(id)sender;

Firstvc.M 档案

@implementation ViewController

-(IBAction)StartQuiz:(id)sender {
Questions *MenuToQuestions = [[Questions alloc]
                              initWithNibName:@"Questions"
                              bundle:nil];

[self.view addSubview:MenuToQuestions.view];

}

SecondVC.h 文件(后退按钮崩溃应用)

SecondVC.h file (Back button crashes app)

 @interface Questions : UIViewController

{

IBOutlet UIButton *BasicOptics;
IBOutlet UIButton *EyeAnatomy;
IBOutlet UIButton *OphthalmicInstruments;
IBOutlet UIButton *Lenses;
IBOutlet UIButton *Transposition;
IBOutlet UIButton *Standards;
IBOutlet UIButton *Frames;
IBOutlet UIButton *Random; 
IBOutlet UIButton *Back;
IBOutlet UILabel *Cat1;
IBOutlet UILabel *Cat2;
IBOutlet UIButton *Right1;
IBOutlet UIButton *Right2;
IBOutlet UIButton *Right3;
IBOutlet UIButton *Right4;
IBOutlet UIButton *Wrong1;
IBOutlet UIButton *Wrong2;
IBOutlet UIButton *Wrong3;
IBOutlet UIButton *Wrong4;
IBOutlet UILabel *Answer1;
IBOutlet UILabel *Answer2;
IBOutlet UILabel *Answer3;
IBOutlet UILabel *Answer4;
IBOutlet UILabel *Question;
IBOutlet UILabel *SelectCategory;
IBOutlet UILabel *Lives;
IBOutlet UILabel *Score;
IBOutlet UILabel *LivesWord;
IBOutlet UILabel *ScoreWord;
IBOutlet UILabel *GameOver;
IBOutlet UILabel *FinalScore;
}

-(IBAction)BasicOptics:(id)sender;
-(IBAction)EyeAnatomy:(id)sender;
-(IBAction)OphthalmicInstruments:(id)sender;
-(IBAction)Lenses:(id)sender;
-(IBAction)Transposition:(id)sender;
-(IBAction)Standards:(id)sender;
-(IBAction)Frames:(id)sender;
-(IBAction)Random:(id)sender;
-(IBAction)Right:(id)sender;
-(IBAction)Wrong:(id)sender;
-(IBAction)Back:(id)sender;

@end

Secondvc.m 文件

Secondvc.m file

-(IBAction)Back:(id)sender {

ViewController *MenuToViewController = [[ViewController alloc]
                              initWithNibName:@"ViewController"
                              bundle:nil];

[self.view addSubview:MenuToViewController.view];

}


推荐答案

没有为您的 MenuToViewController 实例在任何地方保留引用。 MenuToViewController 的视图被添加到视图层次结构中,因此它被保留,但是当视图尝试向其中一个插座发送消息时,您的应用崩溃,因为控制器已被释放。

You are not holding a reference for your MenuToViewController instance anywhere. The view of the MenuToViewController gets added to the view hierarchy, so it gets retained, but as soon as the view tries to send a message to one of the outlets, your app crashes, because the controller has been released.

一旦你创建了控制器,你可以设置它作为实例变量(添加 Questions * MenuToQuestions 到您的 @interface )。

Once you create that controller, you could set it as instance variable (add Questions *MenuToQuestions to your @interface).

这篇关于Ios错误:@auto发布池“EXC_BAD_ACCESS”下的线程1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆