I have a view that I'm displaying modally to get login information from a user. I have the following setup:
- The view controller is a
UITableViewController
- The table has three cells: username and password fields (both of type
UITextField
withinUITableViewCell
) and one simple cell as the login button. - Values are read from
UITextField
intextFieldDidEndEditing:
message - The text fields are identified by different tag values.
The problem
My problem is that when the focus is in a UITextField
and user touches the login button, the respective UITextField
's textFieldDidEndEditing:
message is sent after the didSelectRowAtIndexPath:
. Now the issue here is that I'm sending a message of new user credentials to my LoginViewControllerDelegate
in the didSelectRowAtIndexPath:
and at that time the text field's value is not read yet.
Some Ideas
I have some ideas how to fix this, but I have complications with each of them.
First, I could close the login view and the delegate is notified during the closing, but I want to give the delegate (one who owns this login view) full control and I think it should be the delegate's job to close the login view on successful login (the login view only reads the credentials, the delegate validates these).
Second, I could also read the username or password just before calling the delegate but then I'd have to look up the text fields. If the views are not visible, I think it is wrong to assume that the cells do exist. This is just a big if, but I wan't to make it right. Would it be ok to retain the UITextField
s? This way, however, I can't use some custom cell that would itself provide the textfield.
Basically I want the following:
- Need for (valid) user credentials is detected, login view is popped up
- User inputs the username and password and invokes done.
- The delegate validates these credentials. If they do not work, a message is shown and try step 2 again.
- Credentials are ok, so close the login view and continue.