Ios错误:@auto发布池下的线程1“EXC_BAD_ACCESS

时间:2013-06-25 12:13:48

标签: ios crash exc-bad-access back

当我点击“返回”按钮时,应用程序崩溃并显示此错误。我有2个视图控制器。在第一个vc上,“开始”按钮可以正常切换到第二个视图,但是当我点击“返回”按钮时,应用程序崩溃,我在@autorelease池下面的行上面得到了上面的错误。我也会发布我的开始代码和&后退按钮。谢谢 :)     #进口     #import“AppDelegate.h”

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

第一个vc.H文件开始按钮(这可以切换到第二个视图)

 @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文件(后退按钮崩溃应用)

 @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档案

-(IBAction)Back:(id)sender {

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

[self.view addSubview:MenuToViewController.view];

}

1 个答案:

答案 0 :(得分:1)

您没有在任何地方为MenuToViewController实例提供参考。 MenuToViewController的视图被添加到视图层次结构中,因此它被保留,但是一旦视图尝试向其中一个出口发送消息,您的应用程序就会崩溃,因为控制器已被释放。 / p>

创建该控制器后,您可以将其设置为实例变量(将Questions *MenuToQuestions添加到@interface)。