views:

26

answers:

1

I have three textfields in interface builder being used to accept input. When a button is pushed the data in the 3 fields are processed. Currently, when one of the textfields sends out a textFieldShouldReturn (or similar) message to its delegate, I assign the "sender" parameter (using the tag property) to the delegate's respective UITextField instance variable.

I run into a problem if the button is pushed, but the user has taken no action inside the textfield, essentially leaving the delegate's UITextFields as nil. A simple work around is to just check for nil and assume that nil means an empty textfield, but I'm sure there is a more appropriate pattern within this context to achieve the same goal.

Essentially, how do I assign IB textfields to the delegate UITextField properties without the user taking some action to invoke the delegate?

A: 

If your delegate object is represented in the xib file (it's the owner or something), you could use IBOutlets to connect the textfields to delegate variables. See the Interface Builder User Guide.

If your delegate is not there, there's probably a place in your code that assigns the delegate to the textfield and hence know both of them. You could set the textfield on the delegate at the same time.

Mo