Search code examples
iosuistoryboardsegue

Segue / uncaught exception error


I am trying to create an app with two basic screens, main and set-up. I transition from main to set-up using navigation controllers and segues, I rewind the segue to go from the set-up (screen 2) back to the main. all this works great!

I want to add a table with the help topics listed in the cells and i cannot get the help button to select the correct segue. I keep getting an uncaught exception error because the program is trying to perform he prepare to segue actions and send data back to the main screen. I am quite confused as to how to fix this problem. I used the navigation controllers and segues in lieu of just buttons etc to be more efficient and it seems to be more trouble!

#import "SignalViewController.h"
#import "SetUpViewController.h"

@interface SignalViewController ()

@end

@implementation SignalViewController

-(IBAction)unwindToSignalView:(UIStoryboardSegue *)segue
{

    float minSlider = sensorMin;    //Get Slider range values
    float maxSlider = sensorMax;
    sensorValueSlider.minimumValue = minSlider;         //Set Slider Range
    sensorValueSlider.maximumValue = maxSlider;


    NSString* sensorMinD = [NSString localizedStringWithFormat:@"%.1f",sensorMin];//save default values next 9 lines
    NSString* sensorMaxD = [NSString localizedStringWithFormat:@"%.1f",sensorMax];
    NSString* signalMinD = [NSString localizedStringWithFormat:@"%.1f",signalMin];
    NSString* signalMaxD = [NSString localizedStringWithFormat:@"%.1f",signalMax];

    [labelY1 setText:sensorMinD];//set labels to match settings page next 3 lines
    [labelY3 setText:sensorMaxD];
    [labelX1 setText:signalMinD];
    [labelX3 setText:signalMaxD];

    //NSLog(@"signalMin: %f ", signalMin);
    //NSLog(@"signalMax: %f ", signalMax);
    //NSLog(@"sensorMin: %f ", sensorMin);
    //NSLog(@"sensroMax: %f ", sensorMax);

}


#import "SignalViewController.h"
#import "SetUpViewController.h"

@interface SetUpViewController ()


@end

@implementation SetUpViewController

@synthesize sensorMinY1;
@synthesize sensorMaxY3;
@synthesize signalMinX1;
@synthesize signalMaxX3;
@synthesize sensLabel;
@synthesize sigLabel;
//@synthesize buttonHelpSetUp;



-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    self.view.backgroundColor = [UIColor blueColor];
    SignalViewController *passValue = [segue destinationViewController];
    ***passValue.sensorMin = [[sensorMinY1 text] floatValue];//sensorMinY1;***
    passValue.sensorMax = [[sensorMaxY3 text] floatValue];//sensorMaxY3;
    passValue.signalMin = [[signalMinX1 text] floatValue];//signalMinX1;
    passValue.signalMax = [[signalMaxX3 text] floatValue];//signalMaxX3;
    [passValue.labelSigUnits setText:sigLabel.text];
    [passValue.labelSensUnits setText:sensLabel.text];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setValue:signalMinX1.text forKey:@"X1"];
    [defaults setValue:signalMaxX3.text forKey:@"X3"];
    [defaults setValue:sensorMinY1.text forKey:@"Y1"];
    [defaults setValue:sensorMaxY3.text forKey:@"Y3"];

}

this is the code set up that works. I only added the table view controller then embedded it into a navigation controller. I then ctrl-drag from the help button(toolbar item) to the new navigation controller and created an automatic segue like i did before only this time i get the error, it is getting hung up on the line this is in the asterix above.


Solution

  • prepareForSegue is called for every segue going out of your view controller. If you have multiple segues, you have to give them all identifiers, then check the identifier in prepareForSegue and perform the right actions there.

    At the moment you're assuming that the destination controller for any segue is a SignalViewController.