0

I am having a real headache with his today and could really do with some help / advice.

The Problem

Everything in the code is working well, however i am having huge problem getting textFieldDidFinishEditing to fire correctly it is not being called for what ever reason (prob because i don't understand it) i have got textFieldDidBeginEditing to work fine and am applying the same logic but it simply is not working.

A few things that i have done, the delegate for the fields is set correctly, this again is proved by the KB removing, text fields going gray and nslog output is correct (except for did finish editing).

What it should do is when the user enters a value and then leaves either text field 1 or 2 it populates the other field with the value i.e text1 =2 when the user exits the field the textFieldDidFinishEditing fires and then runs the code to set text field 2 to = 2. but it is not working not even getting called. I know i can set this from the IB with the did end editing sent events however id would rather not use that.

I tried using textFieldDidEndEditing - this does work however it releases the responder before i can pass any values etc, I have read the apple developer section for the UITextField class and believe i am doing it correctly (obviously not as it is not working) so i am at a loss, any help would be apreciated

The Code

Below is a copy of my code

//
//  ViewController.m
//  didendediting
//
//  Created by Developer on 16/06/2013.
//  Copyright (c) 2013 Mr H. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

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



//Checking for edit state on each of the text fields this works fine as does what is expected
- (void)textFieldDidBeginEditing:(UITextField *)textField

{

    if (textField.tag == 0) //text 1 field
    {
        self.text1.backgroundColor = [UIColor lightGrayColor];
        self.text2.backgroundColor = [UIColor whiteColor];
        NSLog(@" Text 1 Became First Responder");
        //self.blockWidth.text=self.blockLength.text;
    }
    else if (textField.tag == 1) //text 2 field
    {
        self.text2.backgroundColor = [UIColor lightGrayColor];
        self.text1.backgroundColor = [UIColor whiteColor];
        NSLog(@" Text 2 Became First Responder");
    }
}

//use this to get rid of the KB when the user clicks anywhere on the screen - again this
//works fins as it removes the kb from screen
- (IBAction)hideKeyboard:(id)sender

{
    [self.text1 resignFirstResponder];
    [self.text2 resignFirstResponder];
    NSLog(@"RESPONDER Released");
}

//This is the area that is not working
- (void)textFieldDidFinishEditing:(UITextField *)textField

{

    if (textField.tag == 0) //text 1 field
    {

        NSLog(@"text 1 finished editing");
        self.text1.text=self.text2.text;

    }

    else if (textField.tag == 1) //text 2 field
    {

        NSLog(@"text 2 finished editing");
       self.text2.text=self.text1.text;
    }

    else
    {
      NSLog(@"something gone wrong");   
    }

}
@end
4

1 回答 1

2

你有这些UITextField 代表

– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:

我想你正在寻找– textFieldDidEndEditing:

于 2013-06-16T15:37:43.627 回答