2013-06-25 44 views
0

當我點擊後退按鈕時,應用程序崩潰並顯示此錯誤我有2個視圖控制器,在第一個vc上,開始按鈕可以很好地切換到第二個視圖,但當我點擊後退按鈕時,應用程序崩潰,我得到上面的錯誤在@autorelease池下面的行。我還將發佈代碼爲我的開始&後退按鈕。thx :) #import #import「AppDelegate.h 「Ios錯誤:在@auto發佈池下的線程1「EXC_BAD_ACCESS

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

你不是抱着你MenuToViewController實例的引用的任何地方。 MenuToViewController的視圖被添加到視圖層次結構中,因此它被保留,但只要視圖試圖向其中一個插座發送消息,您的應用就會崩潰,因爲控制器已被釋放。

一旦您創建了該控制器,您可以將其設置爲實例變量(將Questions *MenuToQuestions添加到您的@interface)。

+0

Thx爲您的迴應。如果你能爲我分手,我是一個新手。 Questions.M中的@interface行應該是這樣的嗎? '@interface Questions * MenuToQuestions:UIViewController' – MrsOptic

+0

請檢查以上評論。謝謝。 – MrsOptic

+0

@MrsOptic不,你不會創建一個像這樣的接口。 – Popeye

相關問題