代码中的错误,但无法弄清楚在哪里(值未导入)

时间:2013-07-30 18:25:52

标签: ios import

我正在构建一个基于主视图控制器(CalViewController)的应用程序来进行数学运算,然后,有两个视图控制器(DrinksViewController& FoodViewController)。

我构建了CalViewController和DrinksViewController,但是当我想复制DrinksViewController来构建FoodViewController(相同的视图使用不同的数据)时出现了一个错误:在PropertyViewController类型的对象上找不到“Property'buffon'

然后在我的foodViewController.h中定义'bouffon',然后由CalViewController导入。它适用于'CaloriesDepensees'(来自DrinksViewController的数据),但不适用于'bouffon'。我检查了DrinksViewController.h和.m中的每一行,它看起来与FoodViewController.h和.m完全相同(显然有不同的数据)。

Custom Class&故事板ID也是此视图控制器的FoodViewController(在故事板中,身份检查器)。

非常感谢您的帮助!

皮尔

这里是CalViewController.h:

#import <UIKit/UIKit.h>
#import "CalAppDelegate.h"
#import "DrinksViewController.h"
#import "FoodViewController.h"

@interface CalViewController : UIViewController
{
    double temps;
    double distance;
    double vitesse;
    double poids;
    NSString *caloriesText;
}
@property (weak, nonatomic) IBOutlet UITextField *saisieTemps;
@property (weak, nonatomic) IBOutlet UITextField *saisieDistance;
@property (weak, nonatomic) IBOutlet UITextField *saisiePoids;
@property (weak, nonatomic) IBOutlet UITextView *resultat;
@property (weak, nonatomic) IBOutlet UISwitch *saisieDefaut;
@property (weak, nonatomic) IBOutlet UILabel *poidsDefaut;

- (IBAction)tempsAction:(id)sender;
- (IBAction)distanceAction:(id)sender;
- (IBAction)defautAction:(id)sender;
- (IBAction)saisieReturn :(id)sender;
- (IBAction)calcul:(id)sender;
- (IBAction)paramSwitch:(id)sender;
- (IBAction)poidsAction:(id)sender;

@end

这里是CalViewController.m:

@interface CalViewController ()

@end

@implementation CalViewController
@synthesize resultat;
@synthesize saisieDistance;
@synthesize saisieTemps;
@synthesize saisiePoids;
@synthesize saisieDefaut;
@synthesize poidsDefaut;

double calories;
double factCal;
double vitesse;
double poidsDonne=75;

- (void)viewDidLoad
{
    [super viewDidLoad];
    calories=1.0;

    if (saisieDefaut.on) {
        saisiePoids.hidden=YES;
        poidsDefaut.hidden=NO;
    }
    else {
        saisiePoids.hidden=NO;
        poidsDefaut.hidden=YES;
    }
    // Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)tempsAction:(id)sender {
    temps = [[saisieTemps text] doubleValue];
}

- (IBAction)distanceAction:(id)sender {
    distance = [[saisieDistance text] doubleValue];
}

- (IBAction)poidsAction:(id)sender {
    poids = [[saisiePoids text] doubleValue];
}



- (IBAction)defautAction:(id)sender {

}

- (IBAction)saisieReturn :(id)sender{
    [sender resignFirstResponder];
}

- (IBAction)calcul:(id)sender {
    temps = [[saisieTemps text] doubleValue];
    distance = [[saisieDistance text] doubleValue];
    vitesse = distance*1000/temps;
    if (vitesse <110)
    factCal=1.06;
    else if (vitesse < 120)
    factCal=1.052;
    else if (vitesse < 130)
    factCal=1.046;
    else if (vitesse < 140)
        factCal=1.041;
    else if (vitesse < 150)
        factCal=1.037;
    else if (vitesse < 160)
        factCal=1.034;
    else if (vitesse < 280)
        factCal=1.030;
    else if (vitesse < 300)
        factCal=1.035;
    else if (vitesse < 320)
        factCal=1.039;
    else if (vitesse < 330)
        factCal=1.043;
    else if (vitesse < 340)
        factCal=1.046;
    else if (vitesse < 350)
        factCal=1.049;
    else if (vitesse < 360)
        factCal=1.052;
    else if (vitesse < 370)
        factCal=1.055;
    else if (vitesse < 380)
        factCal=1.058;
    else if (vitesse < 390)
        factCal=1.049;
    else if (vitesse>=390)
        factCal=1.065;


   if (saisieDefaut.on)
       calories= factCal*distance*poidsDonne;
    else
       calories= factCal*distance*poids;
    resultat.text = [NSString stringWithFormat:@"%0.f", calories];
}

- (IBAction)paramSwitch:(id)sender {
    if (saisieDefaut.on) {
        saisiePoids.hidden=YES;
        poidsDefaut.hidden=NO;
        }
    else {
        saisiePoids.hidden=NO;
        poidsDefaut.hidden=YES;
        }
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"showFoodSegue"]){
        FoodViewController *controller = (FoodViewController *)segue.destinationViewController;
        controller.bouffon = calories;

此处出现错误,'bouffon'未被称为FoodViewController的对象。

    }
    if([segue.identifier isEqualToString:@"showDrinksSegue"]){
            DrinksViewController *controllera = (DrinksViewController *)segue.destinationViewController;
        controllera.caloriesDepensees = calories;

    }
}



@end

这里是FoodViewController.h:

#import <UIKit/UIKit.h>
#import "CalAppDelegate.h"

@interface FoodViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *foodCollectionView;
@property(nonatomic) double bouffon;

@end

这里是FoodViewController.m:

#import "FoodViewController.h"
#import "FoodCell.h"

@interface FoodViewController ()
{
    NSArray *arrayOfImages;
    NSArray *arrayOfDescriptions;
    NSArray *arrayOfCalories;
    double caloriesFoodDouble;
    NSString *caloriesFoodObject;
    double receptionDouble;
}

@end

@implementation FoodViewController
@synthesize bouffon;
@synthesize foodCollectionView;

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

- (void)viewDidLoad
{
    [super viewDidLoad];


    [[self foodCollectionView]setDataSource:self];
    [[self foodCollectionView]setDelegate:self];

    arrayOfImages = [[NSArray alloc]initWithObjects:@"beer2.jpg",@"biere1.png",nil];
    arrayOfDescriptions =[[NSArray alloc]initWithObjects:@"bouffe",@"binouffe",nil];
    arrayOfCalories =[[NSArray alloc]initWithObjects:@"1000",@"10000",nil];
}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{ return [arrayOfDescriptions count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier1=@"Cell1";
    FoodCell *cell1 =  ([collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier1 forIndexPath:indexPath]);


    [[cell1 foodImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
    caloriesFoodObject=[arrayOfCalories objectAtIndex:indexPath.item];
    caloriesFoodDouble = [caloriesFoodObject doubleValue];
    caloriesFoodDouble=caloriesFoodDouble/bouffon;
    [[cell1 foodLabel]setText:[NSString stringWithFormat:@"%.1f%@", caloriesFoodDouble,[arrayOfDescriptions objectAtIndex:indexPath.item]]];

    return cell1;
}

- (NSInteger)numberOfSections:(UICollectionView *) collectionView
{return 1;
}



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

@end

1 个答案:

答案 0 :(得分:0)

经过一段时间的研究,我发现另一个FoodViewController.m已经创建并出现在我的Finder中。

因此,只需检查我的Finder并删除错误的文件。