正在填充的对象显示日志中的空字段(IOS,OBJ-C)

Vanssss

我正在从“标签”中填充对象的字段,当在“日志”中显示时,标签是正确的值,但对象的字段为null。我来自Android / Java背景,这很尴尬。任何帮助将是巨大的。

为了清楚起见,“土壤类型”字段日志显示为“示例”,而“土壤类型”日志显示为(空)

- (IBAction)saveButton:(id)sender {

    Soil *thisSoil = self.thisSoil;

    thisSoil.soilType = self.soilNameField.text;
    NSLog(@"soil  type field %@", self.soilNameField.text);
    NSLog(@"soil type: %@", thisSoil.soilType);

    thisSoil.frictionAngle = [self.frictionAngleValue.text integerValue];

    if ([self.soilUnitsSwitch isOn] ) {
        thisSoil.cohesion = [self.cohesionValue.text doubleValue];
        thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
    }else{
        thisSoil.cohesion = [self.cohesionValue.text doubleValue];
        thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
    }
    [self.delegate SoilCreatorViewController:self didFinishItem:thisSoil];
    [self.navigationController popViewControllerAnimated:YES];
}

整个控制器.m文件

#import "SoilCreatorViewController.h"

#define IMPERIAL_TO_METRIC 0.3048
#define KG_TO_LBS 2.2

@interface SoilCreatorViewController ()

@end

@implementation SoilCreatorViewController


- (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 from its nib.
}

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



- (IBAction)soilQuestions:(id)sender {

        [self popupmaker :@"Friction Angle" : @"Phi is the angle of internal friction for soil, which governs soil strength and resistance. This value should be attained from competent field testing and the judgment of a licensed engineer."];

        [self popupmaker :@"Soil Cohesion": @"Cohesion defines the non-stress dependent shear strength of soil and should be used with caution. Typically,cohesion occurs in stiff, over-consolidated clays or cemented native soils. Cohesion should be neglected if the designer is unsure of its presence."];
}

- (IBAction)SwitchDidChange:(id)sender {
           if ([sender isOn]) {

            self.cohesionUnits.text = @"Ft";
            self.unitWeightUnits.text= @"M";


        }else{
            self.cohesionUnits.text = @"M";
            self.unitWeightUnits.text = @"M";

        }
    }

- (IBAction)unitWtDidChange:(id)sender {
    self.unitWeightValue.text = [NSString stringWithFormat:@"%.1f", (double)self.unitWeightStepper.value];

}

- (IBAction)frictionAngleDidChange:(id)sender {
    self.frictionAngleValue.text = [NSString stringWithFormat:@"%d", (int)self.frictionAngleStepper.value];

}

- (IBAction)cohesionDidChange:(id)sender {
    self.cohesionValue.text = [NSString stringWithFormat:@"%.1f", (double)self.cohesionStepper.value];

}

- (IBAction)textFieldDismiss:(id)sender {

    [[self view] endEditing:YES];
}


- (IBAction)UnitSwitch:(id)sender {

    if ([sender isOn]) {
        self.unitWeightUnits.text = @"LBS/cubic Ft.";
        self.cohesionUnits.text = @"imp";
    }else{
        self.unitWeightUnits.text = @"KG/m3";
        self.cohesionUnits.text = @"met";
    }
}

- (IBAction)cancelButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)saveButton:(id)sender {

    Soil *thisSoil = self.thisSoil;

    thisSoil.soilType = self.soilNameField.text;
    NSLog(@"soil  type field %@", self.soilNameField.text);
    NSLog(@"soil type: %@", thisSoil.soilType);

    thisSoil.frictionAngle = [self.frictionAngleValue.text integerValue];

    if ([self.soilUnitsSwitch isOn] ) {
        thisSoil.cohesion = [self.cohesionValue.text doubleValue];
        thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
    }else{
        thisSoil.cohesion = [self.cohesionValue.text doubleValue];
        thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
    }
    [self.delegate SoilCreatorViewController:self didFinishItem:thisSoil];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)popupmaker:(NSString *)title :(NSString *)message{
    UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:title
                                                     message:message
                                                    delegate:self
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil
                          ];
    [alert show];
}
@end

.h文件

#import "Soil.h"

@class SoilCreatorViewController;

@protocol SoilCreatorViewDelegate <NSObject>
-(void)SoilCreatorViewController:(SoilCreatorViewController *)controller didFinishItem:(Soil *)item;

@property (nonatomic, weak) id <SoilCreatorViewDelegate> delegate;
@end

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





@interface SoilCreatorViewController : UIViewController

@property (nonatomic,weak) id<SoilCreatorViewDelegate> delegate;
@property (weak, nonatomic) IBOutlet UITextField *soilNameField;
@property (weak, nonatomic) IBOutlet UISwitch *soilUnitsSwitch;
@property (nonatomic,strong) Soil  *thisSoil;
@property (weak, nonatomic) IBOutlet UIStepper *frictionAngleStepper;
@property (weak, nonatomic) IBOutlet UIStepper *unitWeightStepper;
@property (weak, nonatomic) IBOutlet UIStepper *cohesionStepper;
@property (weak, nonatomic) IBOutlet UILabel *unitWeightValue;
@property (weak, nonatomic) IBOutlet UILabel *frictionAngleValue;
@property (weak, nonatomic) IBOutlet UILabel *cohesionValue;
@property (weak, nonatomic) IBOutlet UILabel *unitWeightUnits;
@property (weak, nonatomic) IBOutlet UILabel *cohesionUnits;

- (IBAction)soilQuestions:(id)sender;
- (IBAction)SwitchDidChange:(id)sender;
- (IBAction)unitWtDidChange:(id)sender;
- (IBAction)frictionAngleDidChange:(id)sender;
- (IBAction)cohesionDidChange:(id)sender;
- (IBAction)textFieldDismiss:(id)sender;


- (IBAction)cancelButton:(id)sender;
- (IBAction)saveButton:(id)sender;
-(void)popupmaker:(NSString *)title :(NSString *)message;

@end
gnasher729

我看不到任何设置thisSoil的代码。在代码中的某些时候,您需要编写类似

self.thisSoil = [[Soil alloc] init];

或self.thisSoil将永远保持为零。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Obj C-使用数组中特定索引处的对象填充TableView

来自分类Dev

在Obj-C中显示负时间

来自分类Dev

iOS错误转换从Obj-C类继承的Swift中的对象

来自分类Dev

iOS / Obj-C - tableView 中的单元格多次显示相同的数据?

来自分类Dev

在C中向UUEncoder添加空填充

来自分类Dev

C ++在void函数中填充空数组

来自分类Dev

由于空数组iOS obj C,表视图崩溃

来自分类Dev

如何避免在C ++对象中填充?

来自分类Dev

如何避免在C ++对象中填充?

来自分类Dev

从C定义IOS日志

来自分类Dev

C# 填充对象

来自分类Dev

C#映射JSON对象显示为空

来自分类Dev

在C#中显示WPF对象的列表

来自分类Dev

Obj-C UITable 未填充 MutableArray

来自分类Dev

C ++中的对象初始化语法(T obj = {...} vs T obj {...})

来自分类Dev

C# 使用对象字段在列表中查找对象

来自分类Dev

c#newtonsoft json.net在对象内填充json对象导致空值

来自分类Dev

iOS Obj-C 切换多个文本字段的安全文本输入

来自分类Dev

从C#中返回的数据集中填充对象

来自分类Dev

从C#中返回的数据集中填充对象

来自分类Dev

C#检查数组的插槽中是否填充了类对象

来自分类Dev

C中的填充矩阵

来自分类Dev

文本字段验证方法obj c

来自分类Dev

验证C#空字段

来自分类Dev

从目标C中的可变数组中删除空对象

来自分类Dev

Obj-C对象为null

来自分类Dev

C3的JSON对象中的动态字段

来自分类Dev

我可以在C#中访问对象的字段吗

来自分类Dev

使用obj-c在UIAlertView中创建一个文本字段