0

2 つの変数の問題があります。どちらも 12.90 のデフォルト値を持ち、他の変数は 40 であるため、変数値 40 を 45 に変更すると、12.90 も 45 になります。textfielddid 変更イベントによって値を変更しています。

ここに画像の説明を入力

これはイメージです

NSLog(@"Clinical Data %.2f",appDelegate.p_ClinInf_Yes_NV_InModel);
NSLog(@"Fatal Data %.2f",appDelegate.p_Fatal_Yes_NV_InModel);


[textFieldOne addTarget:self action:@selector(textFieldTextDidChangeOneF:) forControlEvents:UIControlEventEditingChanged];


 -(void)textFieldTextDidChangeOneF:(UITextField*)tf{

NSLog(@"Testing Successful Fatal One");


appDelegate.p_Fatal_Yes_NV_InModel  = [[textFieldOne text] floatValue];

appDelegate.p_Fatal_No_NV_InModel=100-appDelegate.p_Fatal_Yes_NV_InModel;
    textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_Fatal_No_NV_InModel];

    NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
    NSString*string=textFieldOne.text;
    if ([string rangeOfCharacterFromSet:set].location != NSNotFound) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Only a  
        number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK"        
       otherButtonTitles:nil];
      [alert show];
      [alert release];
        textFieldOne.text=@"";


    }


    NSLog(@"Fata Data %.2f",appDelegate.p_Fatal_Yes_NV_InModel);

    }

同じボタンで異なるメソッドを呼び出しましたが、この値が競合している可能性があります。

他の方法は

-(void)textFieldTextDidChangeOneCI:(UITextField*)tf{

NSLog(@"Testing Successful");

appDelegate.p_ClinInf_Yes_NV_InModel  = [[textFieldOne text] floatValue];

appDelegate.p_ClinInf_No_NV_InModel=100-appDelegate.p_ClinInf_Yes_NV_InModel;

textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];

NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
NSString*string=textFieldOne.text;
if ([string rangeOfCharacterFromSet:set].location != NSNotFound) {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Only a number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
            textFieldOne.text=@"";


  }

appDelegate.p_ClinInf_No_NV_InModel=100-appDelegate.p_ClinInf_Yes_NV_InModel;

textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];

NSLog(@"p_ClinInf_No_NV_InModel Text Two Data %.2f",appDelegate.p_ClinInf_No_NV_InModel);

 }

読み込み方法を表示

    - (void)viewDidLoad {


appDelegate=[[UIApplication sharedApplication]delegate];
    popImageView.hidden=YES;
closeButton.hidden=YES;

if([titleName isEqualToString:@"Westnile Disease"])
{
    bgImageView.image=[UIImage imageNamed:@"wnd2_bg.png"];
    barImageView.image=[UIImage imageNamed:@"eee1.png"];

    barImageView.image=[UIImage imageNamed:@"eee1.png"];
    labelFour.text=@"99.57";
    labelOne.text=@"12.90";
    labelTwo.text=@"0.43";
    labelThree.text=@"87.10";
    float valueone;
    valueone = appDelegate.p_ClinInf_Yes_NV_InModel;

    textFieldOne.text=[NSString stringWithFormat:@"%.2f",valueone];

        NSLog(@" Working one %.2f",appDelegate.p_ClinInf_Yes_NV_InModel);
        NSLog(@"Working Two %.2f",appDelegate.p_ClinInf_Yes_V_InModel);

        textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];
        textFieldThree.text=[NSString stringWithFormat:@"%.2f", appDelegate.p_ClinInf_Yes_V_InModel];
        textFieldFour.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_V_InModel];
    NSLog(@"Clinical Data %.2f",appDelegate.p_ClinInf_Yes_NV_InModel);
        NSLog(@"Fatal Data %.2f",appDelegate.p_Fatal_Yes_NV_InModel);
       }

if([titleName isEqualToString:@"Eastern Equine Encephalomyelitis"])
 {

    bgImageView.image=[UIImage imageNamed:@"eee2_bg.png"];

    barImageView.image=[UIImage imageNamed:@"eee1.png"];
    textFieldOne.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_Yes_NV_InModel];
    textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];
    textFieldThree.text=[NSString stringWithFormat:@"%.2f", appDelegate.p_ClinInf_Yes_V_InModel];
    textFieldFour.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_V_InModel];

    }

if([titleName isEqualToString:@"Western Equine Encephalomyelitis"])

     {
    bgImageView.image=[UIImage imageNamed:@"wee2_bg.png.png"];
    NSLog(@"appDelegate.p_ClinInf_Yes_NV_InModel %.2f",appDelegate.p_ClinInf_Yes_NV_InModel);
    barImageView.image=[UIImage imageNamed:@"eee1.png"];

        appDelegate.p_ClinInf_No_NV_InModel=100-appDelegate.p_ClinInf_Yes_NV_InModel;

    appDelegate.p_ClinInf_No_V_InModel=100- appDelegate.p_ClinInf_Yes_V_InModel;
    textFieldOne.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_Yes_NV_InModel];
    textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];
    textFieldThree.text=[NSString stringWithFormat:@"%.2f", appDelegate.p_ClinInf_Yes_V_InModel];
    textFieldFour.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_V_InModel];
    }

if([titleName isEqualToString:@"Venezuelan Equine Encephalomyelitis"])  {

    bgImageView.image=[UIImage imageNamed:@"page2_bg.png"];

    barImageView.image=[UIImage imageNamed:@"eee1.png"];
    textFieldOne.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_Yes_NV_InModel];
    textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];
    textFieldThree.text=[NSString stringWithFormat:@"%.2f", appDelegate.p_ClinInf_Yes_V_InModel];
    textFieldFour.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_V_InModel];



    }

  r_Fatal_w_Euthanasia_NV=appDelegate.p_ClinInf_Yes_NV_InModel *     appDelegate.p_Fatal_Yes_NV_InModel * appDelegate.p_Euthanasia_Yes_NV_InModel * 1;

r_Fatal_w_Spontaneous_Death_NV=appDelegate.p_ClinInf_Yes_NV_InModel *appDelegate.p_Fatal_Yes_NV_InModel *appDelegate.p_Euthanasia_No_NV_InModel * 1;

r_NonFatal_w_Perpetual_Sequelae_NV=appDelegate.p_ClinInf_Yes_NV_InModel *appDelegate.p_Fatal_No_NV_InModel * 1 * appDelegate.p_Sequelae_Yes_NV_InModel;
r_NonFatal_w_Full_Recovery_NV=appDelegate.p_ClinInf_Yes_NV_InModel * appDelegate.p_Fatal_No_NV_InModel * 1 * appDelegate.p_Sequelae_No_NV_InModel;
r_Subtotal_ClinInf_NV=r_Fatal_w_Euthanasia_NV + r_Fatal_w_Spontaneous_Death_NV + r_NonFatal_w_Perpetual_Sequelae_NV + r_NonFatal_w_Full_Recovery_NV;

r_Fatal_w_Euthanasia_V= appDelegate.p_ClinInf_Yes_V_InModel * p_Fatal_Yes_V_InModel * appDelegate.p_Euthanasia_Yes_V_InModel * 1;
r_Fatal_w_Spontaneous_Death_V= appDelegate.p_ClinInf_Yes_V_InModel * appDelegate.p_Fatal_Yes_V_InModel *appDelegate.p_Euthanasia_No_V_InModel * 1;
r_NonFatal_w_Perpetual_Sequelae_V= appDelegate.p_ClinInf_Yes_V_InModel * appDelegate.p_Fatal_No_V_InModel * 1 * appDelegate.p_Sequelae_Yes_V_InModel;
r_NonFatal_w_Full_Recovery_V=appDelegate.p_ClinInf_Yes_V_InModel * appDelegate.p_Fatal_No_V_InModel * 1 * appDelegate.p_Sequelae_No_V_InModel;

r_Subtotal_ClinInf_V=r_Fatal_w_Euthanasia_V + r_Fatal_w_Spontaneous_Death_V + r_NonFatal_w_Perpetual_Sequelae_V + r_NonFatal_w_Full_Recovery_V;

/*********************Unvaccinated horse Graph Values **********/

   r_Fatal_V=r_Fatal_w_Spontaneous_Death_V + r_Fatal_w_Euthanasia_V;



[textFieldOne addTarget:self action:@selector(textFieldTextDidChangeOneCI:) forControlEvents:UIControlEventEditingChanged];
[textFieldThree addTarget:self action:@selector(textFieldTextDidChangeThreeCI:) forControlEvents:UIControlEventEditingChanged];

[super viewDidLoad];
    }
4

1 に答える 1

0

メソッドで次の行をコメントするだけtextFieldTextDidChangeOneFです..

textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_No_NV_InModel];

アップデート:

BOOL最初にこの名前で.hファイルに変数を宣言してisTextFieldOneから、次のようなことを行います...

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == textFieldOne) {
        isTextFieldOne = True;
    }
    else{
        isTextFieldOne = False;
    }
    return YES;
}

そして、次のメソッドをあなたのメソッドに置き換えます...

-(void)textFieldTextDidChangeOneF:(UITextField*)tf{

   if (isTextFieldOne){

       NSLog(@"Testing Successful Fatal One");
       appDelegate.p_Fatal_Yes_NV_InModel  = [[textFieldOne text] floatValue];
       appDelegate.p_Fatal_No_NV_InModel=100-appDelegate.p_Fatal_Yes_NV_InModel;
       textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_Fatal_No_NV_InModel];

       NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
       NSString*string=textFieldOne.text;
       if ([string rangeOfCharacterFromSet:set].location != NSNotFound) {
           UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Only a  
        number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK"        
       otherButtonTitles:nil];
           [alert show];
           [alert release];
           textFieldOne.text=@"";
       }
       NSLog(@"Fata Data %.2f",appDelegate.p_Fatal_Yes_NV_InModel);
    }
}
于 2013-03-25T05:29:28.413 に答える