我有一个文本字段,我需要用户在其中输入一个数字,我需要将此数字转换为浮点值并将其带到另一个视图。我找不到我的错误... Xcode 说它在“ float valor = [[_inserir.text ] floatvalue];
”行。如果有人能找到我的错误在哪里,谢谢。
第一个视图.h:
#import <UIKit/UIKit.h>
@interface CedulasFirstViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *inserir;
- (IBAction)calc:(id)sender;
@end
第一个视图.m:(我的变量名前的下划线,xcode自己放的,取出来不会改变任何东西)
#import "CedulasFirstViewController.h"
#import "CedulasSecondViewController.h"
@interface CedulasFirstViewController ()
@end
@implementation CedulasFirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 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)calc:(id)sender {
float valor = [[_inserir.text ] floatvalue];
CedulasSecondViewController *second [[[CedulasSecondViewController alloc] init]];
second.valor = self.valor;
}
@end
第二个视图.h:
#import <UIKit/UIKit.h>
@interface CedulasSecondViewController : UIViewController{
}
@end
第二个视图.m:
#import "CedulasSecondViewController.h"
@interface CedulasSecondViewController ()
@end
@implementation CedulasSecondViewController
- (void)viewDidLoad
{
NSString *numberFromTF [[NSString alloc] initWithFormat:@"%.2f", valor];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
谢谢
编辑:
如果有人能解释一下为什么 xcode 说要在变量之前加上这个下划线