Question

I have mulitple UITextFields in a view.

I'm assuming the place to capture the vlue of a UITextField once the user comes out of it is to implement the delegate method "textFieldShouldReturn".

Question - In "textFieldShouldReturn" however, how do I tell which of the UITextField's triggered this?

For example assuming at this stage I now need to update my data model with the value of what the UITextField now shows, so need to update the correct field in the model with aligns with that particular UITextField.

PS If there's a better approach, or a way to kind of "binding" approach I'm missing I'd be interested

Was it helpful?

Solution

...or you can skip all the tags and make your UITextViews instance vars and do:

- (void)viewDidLoad {
    myTextView1 = [[UITextView alloc] init];
    myTextView2 = [[UITextView alloc] init];
    myTextView3 = [[UITextView alloc] init];
    myTextView4 = [[UITextView alloc] init];
    ......
}

- (void)textFieldShouldReturn:(UITextField *)textField {
    BOOL shouldReturn = NO;

    if (textField == myTextView1)
    {
        shouldReturn = YES;
    }

    ...and so on...

    }

... release the instance vars in the dealloc...

I kinda prefer this way, but the other answer will work too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top