I have an UITableViewController and it is registered for multiple UITableViewCells. In a cell there is a UITextField and I can't set its tag property. It is always taken from Xib file. It doesn't get tag from the code. Here the code I use. What is wrong here?
I expect here the textfield tag should be 1,2 or 3 but it gets always 0 or any value in the xib file.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1) {
TextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextFieldTableCell forIndexPath:indexPath];
cell.delegate = self;
cell.theTextField.tag = InputTypeCompanyName;
NSString *savedString = [self.coreDataWrapper getTheValueOfTextFieldWithAttribute:COMPANY_NAME];
if (![savedString isEqualToString:@""]) {
cell.theTextField.text = savedString;
}
return cell;
} else if (indexPath.section == 4) {
TextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextFieldTableCell forIndexPath:indexPath];
cell.delegate = self;
if (indexPath.row == 0) {
cell.theTextField.placeholder = @"Kullanıcı adı";
cell.theTextField.tag = InputTypeCustomerName;
NSString *savedString = [self.coreDataWrapper getTheValueOfTextFieldWithAttribute:CUSTOMER_NAME];
if (![savedString isEqualToString:@""]) {
cell.theTextField.text = savedString;
}
} else {
cell.theTextField.placeholder = @"Şifre";
cell.theTextField.tag = InputTypeCustomerPassword;
NSString *savedString = [self.coreDataWrapper getTheValueOfTextFieldWithAttribute:CUSTOMER_PASSWORD];
if (![savedString isEqualToString:@""]) {
cell.theTextField.text = savedString;
}
}
return cell;
} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingsCellIdentifier forIndexPath:indexPath];
return cell;
}
}
I expect here the textfield tag should be 1,2 or 3 but it gets always 0 or any value in the xib file.