0

我在尝试将一堆变量从一个类传递到另一个类时出错,我的第一个类控制一个视图,而我的另一个类是一个控制表视图的 tableviewcontroller,我有一个名为“shoplistSegue”的segue,当我单击一个按钮,它使用“prepareForSegue”方法执行 segue 并传递变量。但是当我单击该按钮时,它会冻结并出现错误“无法识别的选择器已发送到实例 0x74af950”。

类1.h

@interface CalcularViewController : UIViewController{

    int calcularIntHomens;
    int calcularIntMulheres;
    int calcularIntCriancas;

}
@property (strong, nonatomic) IBOutlet UILabel *calcularLabelHomens;
@property (strong, nonatomic) IBOutlet UILabel *calcularLabelMulheres;
@property (strong, nonatomic) IBOutlet UILabel *calcularLabelCriancas;
@property (strong, nonatomic) IBOutlet UILabel *calcularLabelFantasmas;
@property int calcularIntHomens;
@property int calcularIntMulheres;
@property int calcularIntCriancas;
- (IBAction)subtractHomens:(id)sender;
- (IBAction)subtractMulheres:(id)sender;
- (IBAction)subtractCriancas:(id)sender;
- (IBAction)addHomens:(id)sender;
- (IBAction)addMulheres:(id)sender;
- (IBAction)addCriancas:(id)sender;
- (IBAction)showResultsIfNotNull:(id)sender;

@end

类1.m

#import "CalcularViewController.h"
#import "ResultadoViewController.h"

@interface CalcularViewController ()

@end

@implementation CalcularViewController
@synthesize calcularIntCriancas, calcularIntHomens, calcularIntMulheres, calcularLabelCriancas, calcularLabelHomens, calcularLabelMulheres, calcularLabelFantasmas;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)subtractHomens:(id)sender {

    if (calcularIntHomens > 0) {
    calcularIntHomens = calcularIntHomens -1;
    NSString *submen = [[NSString alloc] initWithFormat:@"%i", calcularIntHomens];
    calcularLabelHomens.text = submen;
    }

}
- (IBAction)subtractMulheres:(id)sender{

    if (calcularIntMulheres > 0) {
    calcularIntMulheres = calcularIntMulheres -1;
    NSString *subwoman = [[NSString alloc] initWithFormat:@"%i", calcularIntMulheres];
    calcularLabelMulheres.text = subwoman;
    }

}
- (IBAction)subtractCriancas:(id)sender{

    if (calcularIntCriancas > 0) {
    calcularIntCriancas = calcularIntCriancas -1;
    NSString *subchild = [[NSString alloc] initWithFormat:@"%i", calcularIntCriancas];
    calcularLabelCriancas.text = subchild;
    }
}
- (IBAction)addCriancas:(id)sender{

    calcularIntCriancas = calcularIntCriancas +1;
    NSString *addchild = [[NSString alloc] initWithFormat:@"%i", calcularIntCriancas];
    calcularLabelCriancas.text = addchild;
}
- (IBAction)addHomens:(id)sender{

    calcularIntHomens = calcularIntHomens +1;
    NSString *addmen = [[NSString alloc] initWithFormat:@"%i", calcularIntHomens];
    calcularLabelHomens.text = addmen;
}
- (IBAction)addMulheres:(id)sender{

    calcularIntMulheres = calcularIntMulheres +1;
    NSString *addwoman = [[NSString alloc] initWithFormat:@"%i", calcularIntMulheres];
    calcularLabelMulheres.text = addwoman;
}

-(IBAction)showResultsIfNotNull:(id)sender{

    if (calcularIntHomens == 0) {
        if (calcularIntMulheres == 0) {
            if (calcularIntCriancas == 0) {
                calcularLabelFantasmas.text = @"Você vai fazer um churrasco pra fantasmas?";
            } else {
                [self performSegueWithIdentifier:@"resultadoSegue" sender:self];
            }
        } else {
            [self performSegueWithIdentifier:@"resultadoSegue" sender:self];

        }
    } else {
        [self performSegueWithIdentifier:@"resultadoSegue" sender:self];

    }

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"resultadoSegue"]) {

        ResultadoViewController *resultados = [segue destinationViewController];

        resultados.resultadoIntCriancas = calcularIntCriancas;
        resultados.resultadoIntHomens = calcularIntHomens;
        resultados.resultadoIntMulheres = calcularIntMulheres;

    }
}
@end

类2.h

#import <UIKit/UIKit.h>

@interface ResultadoViewController : UIViewController{

    int resultadoIntHomens;
    int resultadoIntMulheres;
    int resultadoIntCriancas;
    IBOutlet UIScrollView *scroller;
    float resultadoGado;
    float resultadoFrango;
    float resultadoPorco;
    float resultadoLinguica;
    float resultadoQueijo;
    float resultadoPaodealho;
    float resultadoAcompanhamento;
    float resultadoAbacaxiassado;
    float resultadoCebolaassada;
    float resultadoBebidas;
    float resultadoAlcool;
    int areThereBebidas;
    BOOL picanhaBOOL;
    BOOL alcatraBOOL;
    BOOL maminhaBOOL;
    BOOL contrafileBOOL;
    BOOL lombinhoBOOL;
    BOOL linguicaBOOL;
    BOOL coracaoBOOL;
    BOOL asaBOOL;
    BOOL coxaBOOL;
    BOOL queijoBOOL;
    BOOL paodealhoBOOL;
    BOOL arrozBOOL;
    BOOL farofaBOOL;
    BOOL vinagreteBOOL;
    BOOL maionesesaladaBOOL;
    BOOL saladaBOOL;
    BOOL abacaxiassadoBOOL;
    BOOL cebolaBOOL;
    BOOL cervejaBOOL;
    BOOL refriBOOL;
    BOOL aguaBOOL;
    BOOL vodkaBOOL;
    BOOL sucoBOOL;
    int gadoTotal;
    int frangoTotal;
    int acompanhamentoTotal;
    int bebidaTotal;
    int something;
    int alcoolTotal;


}
@property int alcoolTotal;
@property int areThereBebidas;
@property float resultadoAlcool;
@property int resultadoIntHomens;
@property int resultadoIntMulheres;
@property int resultadoIntCriancas;
@property float resultadoGado;
@property float resultadoFrango;
@property float resultadoPorco;
@property float resultadoLinguica;
@property float resultadoQueijo;
@property float resultadoPaodealho;
@property float resultadoAcompanhamento;
@property float resultadoAbacaxiassado;
@property float resultadoCebolaassada;
@property float resultadoBebidas;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelPicanha;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAlcatra;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelMaminha;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelContrafile;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelLombinho;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelLinguica;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCoracao;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAsa;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCoxa;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelQueijo;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelPaodealho;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelArroz;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelFarofa;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelVinagrete;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSaladamaionese;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSalada;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAbacaxiassado;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCebola;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCerveja;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelRefri;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAgua;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelVodka;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSuco;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelFome;
- (IBAction)addPicanha:(id)sender;
- (IBAction)addAlcatra:(id)sender;
- (IBAction)addMaminha:(id)sender;
- (IBAction)addContrafile:(id)sender;
- (IBAction)addLombinho:(id)sender;
- (IBAction)addLinguica:(id)sender;
- (IBAction)addCoracao:(id)sender;
- (IBAction)addAsa:(id)sender;
- (IBAction)addCoxa:(id)sender;
- (IBAction)addQueijo:(id)sender;
- (IBAction)addPaodealho:(id)sender;
- (IBAction)addArroz:(id)sender;
- (IBAction)addFarofa:(id)sender;
- (IBAction)addVinagrete:(id)sender;
- (IBAction)addSaladamaionese:(id)sender;
- (IBAction)addSalada:(id)sender;
- (IBAction)addAbacaxi:(id)sender;
- (IBAction)AddCebola:(id)sender;
- (IBAction)addCerveja:(id)sender;
- (IBAction)addRefri:(id)sender;
- (IBAction)addAgua:(id)sender;
- (IBAction)addVodka:(id)sender;
- (IBAction)addSuco:(id)sender;
- (IBAction)buttonBack:(id)sender;
- (IBAction)buttonNext:(id)sender;
@property BOOL picanhaBOOL;
@property BOOL alcatraBOOL;
@property BOOL maminhaBOOL;
@property BOOL contrafileBOOL;
@property BOOL lombinhoBOOL;
@property BOOL linguicaBOOL;
@property BOOL coracaoBOOL;
@property BOOL asaBOOL;
@property BOOL coxaBOOL;
@property BOOL queijoBOOL;
@property BOOL paodealhoBOOL;
@property BOOL arrozBOOL;
@property BOOL farofaBOOL;
@property BOOL vinagreteBOOL;
@property BOOL maionesesaladaBOOL;
@property BOOL saladaBOOL;
@property BOOL abacaxiassadoBOOL;
@property BOOL cebolaBOOL;
@property BOOL cervejaBOOL;
@property BOOL refriBOOL;
@property BOOL aguaBOOL;
@property BOOL vodkaBOOL;
@property BOOL sucoBOOL;
@property int gadoTotal;
@property int frangoTotal;
@property int acompanhamentoTotal;
@property int bebidaTotal;
@property int something;


@end

类2.m

#import "ResultadoViewController.h"
#import "ShoplistViewController.h"

@interface ResultadoViewController ()

@end

@implementation ResultadoViewController
@synthesize resultadoIntCriancas, resultadoIntHomens, resultadoIntMulheres, resultadoAbacaxiassado, resultadoAcompanhamento, resultadoBebidas, resultadoCebolaassada, resultadoFrango, resultadoGado, resultadoLinguica, resultadoPaodealho, resultadoPorco, resultadoQueijo, resultadoLabelAbacaxiassado, resultadoLabelAgua, resultadoLabelAlcatra, resultadoLabelArroz, resultadoLabelAsa, resultadoLabelCebola, resultadoLabelCerveja, resultadoLabelContrafile, resultadoLabelCoracao, resultadoLabelCoxa, resultadoLabelFarofa, resultadoLabelFome, resultadoLabelLinguica, resultadoLabelLombinho, resultadoLabelMaminha, resultadoLabelPaodealho, resultadoLabelPicanha, resultadoLabelQueijo, resultadoLabelRefri, resultadoLabelSalada, resultadoLabelSaladamaionese, resultadoLabelSuco, resultadoLabelVinagrete, resultadoLabelVodka, picanhaBOOL, alcatraBOOL, lombinhoBOOL, contrafileBOOL, maminhaBOOL, linguicaBOOL, coracaoBOOL, queijoBOOL, asaBOOL, coxaBOOL, paodealhoBOOL, arrozBOOL, farofaBOOL, vinagreteBOOL, saladaBOOL, maionesesaladaBOOL, abacaxiassadoBOOL, cebolaBOOL, cervejaBOOL, refriBOOL, aguaBOOL, sucoBOOL, vodkaBOOL, gadoTotal, something, frangoTotal, acompanhamentoTotal, bebidaTotal, resultadoAlcool, areThereBebidas, alcoolTotal;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(void)viewDidAppear:(BOOL)animated{

    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 1035)];


    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    backButton.frame     = CGRectMake(20, 986, 108, 30);
    [backButton setTitle:@"Voltar" forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(buttonBack:) forControlEvents:UIControlEventTouchUpInside];
    [scroller addSubview:backButton];

    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    nextButton.frame     = CGRectMake(192, 986, 108, 30);
    [nextButton setTitle:@"Continuar..." forState:UIControlStateNormal];
    [nextButton addTarget:self action:@selector(buttonNext:) forControlEvents:UIControlEventTouchUpInside];
    [scroller addSubview:nextButton];

}

- (void)viewDidLoad
{

    gadoTotal = 0;

    something = 0;

    resultadoGado = resultadoIntHomens * 0.400 + resultadoIntMulheres * 0.355 + resultadoIntCriancas * 0.200;

    resultadoLinguica = resultadoIntHomens * 0.070 + resultadoIntMulheres * 0.050 + resultadoIntCriancas * 0.030;

    resultadoPorco = resultadoIntHomens * 0.060 + resultadoIntMulheres * 0.035 + resultadoIntCriancas * 0.030;

    resultadoFrango = resultadoIntHomens *  0.085 + resultadoIntMulheres * 0.055 + resultadoIntCriancas * 0.042;

    resultadoQueijo = resultadoIntHomens *  0.050 + resultadoIntMulheres * 0.040 + resultadoIntCriancas * 0.020;

    resultadoAcompanhamento = resultadoIntHomens *  0.225 + resultadoIntMulheres * 0.190 + resultadoIntCriancas * 0.100;

    resultadoAbacaxiassado = resultadoIntHomens *  0.040 + resultadoIntMulheres * 0.025 + resultadoIntCriancas * 0.020;

    resultadoCebolaassada = resultadoIntHomens *  0.050 + resultadoIntMulheres * 0.035 + resultadoIntCriancas * 0.020;

    resultadoPaodealho = resultadoIntHomens *  0.070 + resultadoIntMulheres * 0.045 + resultadoIntCriancas * 0.030;

    resultadoAlcool = resultadoIntHomens *  0.600 + resultadoIntMulheres * 0.350 + resultadoIntCriancas * 0.000;

    resultadoBebidas = resultadoIntHomens *  0.500 + resultadoIntMulheres * 0.650 + resultadoIntCriancas * 0.700;



    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)buttonBack:(id)sender{

    [self performSegueWithIdentifier:@"backtoCalcSegue" sender:self];

}

-(IBAction)buttonNext:(id)sender{

    if (gadoTotal > 0){
        [self performSegueWithIdentifier:@"shoplistSegue" sender:self];
}else { resultadoLabelFome.text = @"Assim as pessoas vão morrer de fome!";}

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"shoplistSegue"]) {

        ShoplistViewController *resultados = [segue destinationViewController];

        resultados.shoplistPicanha = [resultadoLabelPicanha.text floatValue];
        resultados.shoplistAlcatra = [resultadoLabelAlcatra.text floatValue];
        resultados.shoplistMaminha = [resultadoLabelMaminha.text floatValue];
        resultados.shoplistContrafile = [resultadoLabelContrafile.text floatValue];
        resultados.shoplistLombinho = [resultadoLabelLombinho.text floatValue];
        resultados.shoplistLinguica = [resultadoLabelLinguica.text floatValue];
        resultados.shoplistAsa = [resultadoLabelAsa.text floatValue];
        resultados.shoplistCoxa = [resultadoLabelCoxa.text floatValue];
        resultados.shoplistCoracao = [resultadoLabelCoracao.text floatValue];
        resultados.shoplistQueijo = [resultadoLabelQueijo.text floatValue];
        resultados.shoplistPaodealho = [resultadoLabelPaodealho.text floatValue];
        resultados.shoplistArroz = [resultadoLabelArroz.text floatValue];
        resultados.shoplistFarofa = [resultadoLabelFarofa.text floatValue];
        resultados.shoplistVinagrete = [resultadoLabelVinagrete.text floatValue];
        resultados.shoplistMaionese = [resultadoLabelSaladamaionese.text floatValue];
        resultados.shoplistSalada = [resultadoLabelSalada.text floatValue];
        resultados.shoplistAbacaxi = [resultadoLabelAbacaxiassado.text floatValue];
        resultados.shoplistCebola = [resultadoLabelCebola.text floatValue];
        resultados.shoplistAgua = [resultadoLabelAgua.text floatValue];
        resultados.shoplistCerveja = [resultadoLabelCerveja.text floatValue];
        resultados.shoplistRefri = [resultadoLabelRefri.text floatValue];
        resultados.shoplistVodka = [resultadoLabelVodka.text floatValue];
        resultados.shoplistSuco = [resultadoLabelSuco.text floatValue];

    }
}

@end

编辑:

在我删除目标视图并将其再次放在那里之前,它工作正常,因为它在界面生成器上有一个小问题。当我把它放在那里时,我又把控制类和它之前的所有东西放在了检查员身上......

4

2 回答 2

4

这就是问题:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"shoplistSegue"]) {

    ShoplistViewController *resultados = [segue destinationViewController];

    resultados.shoplistPicanha = [resultadoLabelPicanha.text floatValue];

要么ShoplistViewController没有实现-setShoplistPicanha:/没有@property (readwrite) shopListPicanha ,要么你[segue destinationViewController]没有返回你认为它所做的(即不是 ShoplistViewController)。

于 2013-01-31T15:51:37.923 回答
0

你试着打电话

 UITableViewController  setShoplistPicanha:

显然它没有定义(有一个论点)

于 2013-01-31T15:41:59.227 回答