Forms XCode 4.5表单验证

Forms XCode 4.5表单验证,forms,validation,Forms,Validation,我在xcode 4.5中有一个单视图应用程序,试图学习表单验证。2个文本框,1个标签,共2个按钮,计算乘法和1个清除按钮设置文本和标签,我试图测试,但得到一些奇怪的结果。我是visualstudios用户,习惯于设置一个断点,然后将鼠标移到一个变量上,查看它的值,但xcode并不是这样。我试过测试==零,但没有成功。如果我第一次点击calculate,并且从来没有输入过任何我的测试不起作用的东西。它既不是零,也可能不是未定义的。然后我在text1中输入3,在text2中没有输入任何内容,我就会收

我在xcode 4.5中有一个单视图应用程序,试图学习表单验证。2个文本框,1个标签,共2个按钮,计算乘法和1个清除按钮设置文本和标签,我试图测试,但得到一些奇怪的结果。我是visualstudios用户,习惯于设置一个断点,然后将鼠标移到一个变量上,查看它的值,但xcode并不是这样。我试过测试==零,但没有成功。如果我第一次点击calculate,并且从来没有输入过任何我的测试不起作用的东西。它既不是零,也可能不是未定义的。然后我在text1中输入3,在text2中没有输入任何内容,我就会收到警报 我点击清除并执行text2,但不是text1,我的测试工作正常。我输入text1,点击计算,得到警报,然后删除text1,输入text2,没有警报。除非我在两次尝试之间清除,否则警报不会工作。因为我最终需要检查数字,所以我尝试了

 float a=([text1.text floatValue]);
 float b=([text1.text floatValue]);
 if(a==NaN||b==NaN){
 }
但这两种方法都不行,我会出错。我知道我是新来的,但这是一个痛苦…下面是我的代码,请对我放松

//
//  ViewController.m
//  calc2
//
//  Created by russell on 11/18/12.
//  Copyright (c) 2012 russell. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (IBAction)button1{

if (text1.text==@""||text2.text==@"") {


    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Blank Values"
                                                     message:@"You cannot multiply blanks"
                                                    delegate:self
                                                    cancelButtonTitle:@"Ok"
                                                    otherButtonTitles:nil]
                                                    autorelease];
    // optional - add more buttons:

    [alert show];

} else {
    float x=([text1.text floatValue]);
    float c=x*([text2.text floatValue]);
    label1.text=[[NSString alloc]initWithFormat:@"%.2f",c];
}



}

- (IBAction)button2{
text1.text=@"";
text2.text=@"";
label1.text=@"";
}


- (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.
}

@end