MrsOptic
MrsOptic

Reputation: 5

Back button crashes app

I have a 2vcs. Main vc is *ViewController and the other *Questions. The start button works fine in taking me to Questions.vc but the app crashes when I try to go back to ViewController.vc from Questions.vc. The Quit button is declared in Questions.H and the button is linked up, but the app crashes once I b&r and hit the quit button.

After turning on all Exception breakpoints. It shows 10 breakpoints with 3 disabled. These are the lines of code: Questions.H all three of these lines

`

-(IBAction)OphthalmicInstruments:(id)sender;

-(IBAction)Lenses:(id)sender;

-(IBAction)Transposition:(id)sender;

`

Questions.M (the blue arrow points to the space b/t these two lines `

-(IBAction)OphthalmicInstruments:(id)sender{

    Cat1.hidden = YES;

` Questions.M Lines with blue arrow Case 2 Answer 3 & Case 3 Wrong 4

`

      case 2:
            Question.text = [NSString stringWithFormat:@"A tonometer measures:"];
            Right3.hidden = NO;
            Wrong2.hidden = NO;
            Wrong3.hidden = NO;
            Wrong4.hidden = NO;
            Answer1.text = [NSString stringWithFormat:@"Interpupillary distance"];
            Answer2.text = [NSString stringWithFormat:@"Vertex distance"];
            Answer3.text = [NSString stringWithFormat:@"Intraocular pressure"];
            Answer4.text = [NSString stringWithFormat:@"Basecurve"];
            break;
        case 3: 
            Question.text = [NSString stringWithFormat:@"A lens clock measures:"];
            Right4.hidden = NO;
            Wrong2.hidden = NO;
            Wrong3.hidden = NO;
            Wrong4.hidden = NO;
            Answer1.text = [NSString stringWithFormat:@"Interpupillary distance"];
            Answer2.text = [NSString stringWithFormat:@"Vertex distance"];
            Answer3.text = [NSString stringWithFormat:@"Intraocular pressure"];
            Answer4.text = [NSString stringWithFormat:@"Basecurve"];
            break;

` Questions.M lines: break & case 8 lines both have blue arrows

`

        case 7:
        Question.text = [NSString stringWithFormat:@"The power of a lens is measured in    
_____."];
        Right4.hidden = NO;
        Wrong2.hidden = NO;
        Wrong3.hidden = NO;
        Wrong4.hidden = NO;
        Answer1.text = [NSString stringWithFormat:@"Millimeters"];
        Answer2.text = [NSString stringWithFormat:@"Inches"];
        Answer3.text = [NSString stringWithFormat:@"Nanometers"];
        Answer4.text = [NSString stringWithFormat:@"Diopters"];
        break;
    case 8:
        Question.text = [NSString stringWithFormat:@"A lens with a power of 1 Diopter has a focal length of _____."];

`

Upvotes: 0

Views: 758

Answers (2)

Joe Marion
Joe Marion

Reputation: 406

I was creating something really similar and ran into the same problem. What I did was changed the code that went back and forth between VCs.

So for mine I changed it to First is my main page Viewcontroller to Questions in my ViewController.m

-(IBAction)StartQuiz:(id)sender{

Questions *MenuToQuestions = [[Questions alloc] initWithNibName:nil bundle:nil];
MenuToQuestions.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:MenuToQuestions animated:YES completion:nil];

}

Now here is what I have in my Questions.m

-(IBAction)Back:(id)sender{

[self dismissViewControllerAnimated:NO completion:nil];

}

Upvotes: 2

Popeye
Popeye

Reputation: 12093

1) What does this have to do with xcode? Answer : Nothing So please don't use that tag.

2) Your app doesn't crash at return UIApplicationMain(... it says it does cause your not catching the error/exception. To find out where it is breaking you need to be adding in a Catch all exceptions.

You can do this by going to the Exceptions section of the Navigation controller in xcode.

xcode exceptions window

Once you have navigated here you will notice a + at the bottom left of the window. Select this so it brings up another small window with two options

Exception options

You will need to select Add Exception Breakpoint

Once you have selected this you will get a new window

All exceptions

All you need to do is leave the default settings in and click Done unless you want to play with them. This will make it so when the exception is throw it should bring at the line it crashes on or the general area making it easier to identify the issue.

This might not solve your issue but it is a step closer to solving it. When you get the general area of the error please comment and I will update my answer to include how to solve it, if I can.

Upvotes: 0

Related Questions