Reputation: 1832
I'm having three textfields
inside tableview. I need to set range for each textfield
like:
TextField1
-> MobileNumber -> I not allow user to type more than 10 digit
Textfield2
-> PostalCode -> I not allow user to type more than 6 digit
Textfield3
-> UserName -> I not allow user to leave first character as empty
Upvotes: 0
Views: 378
Reputation: 6110
Assuming that the 3 text fields are in the same cell:
Create 3 different UITextField
s in the UI Builder and put them inside a cell in the table view.
Click on the first text field and from the attributes inspector set its tag property to 1. Set the tag property of the 2 other text fields to 2 and 3.
Now, in your cellForRowAtIndex
method and at the index of the cell that contains the 3 text fields:
if let mobileNumberTextField = cell.viewWithTag(1) as UITextField {
// Customize mobileNumberTextField
}
if let postalCodeTextField = cell.viewWithTag(2) as UITextField {
// Customize postalCodeTextField
}
if let userNameTextField = cell.viewWithTag(3) as UITextField {
// Customize userNameTextField
}
You can achieve the same result by subclassing UITableViewCell
and making the 3 text fields properties in it.
Upvotes: 1