Programatically манипулируя UITextField в клетке, которая была создана в раскадровке
Я пытаюсь изменить UITextField в качестве делегата TableView
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure cell here
if (indexPath.section == [self nameSectionNumber]) {
if (indexPath.row == [self firstNameRowNumber]){
UITextField *textFieldFromCell = [self retrieveUITextFieldFromCell:cell];
textFieldFromCell.text = [self.person firstName];
} else if (indexPath.row == [self lastNameRowNumber]) {
cell.textLabel.text = [self.person lastName];
}
} else if (indexPath.section == [self emailSectionNumber]) {
if (indexPath.row == [self emailSectionHomeRowNumber]) {
cell.textLabel.text = [self.person homeEmail];
} else if (indexPath.row == [self emailSectionWorkRowNumber]) {
cell.textLabel.text = [self.person workEmail];
}
}
return cell;
}
- (UITextField *)retrieveUITextFieldFromCell:(UITableViewCell *)cell
{
// Need to grab UITextField from cell
for (UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UITextField class]]){
UITextField* txtField = (UITextField *)view;
return txtField;
}
}
return nil;
}
Если я не пытаюсь изменить ячейку и просто сделать
// Configure cell here
if (indexPath.section == [self nameSectionNumber]) {
if (indexPath.row == [self firstNameRowNumber]){
cell.textLabel.text = [self.person firstName];
} else if (indexPath.row == [self lastNameRowNumber]) {
cell.textLabel.text = [self.person lastName];
}
}
UILabel («First Name») ушел и UITextField нет, чего я ожидал, так как я думаю, что его из-за этого кода
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
Примечание: Игнорировать фамилию и адрес электронной поля. На данный момент я только фокусируюсь на имени, чтобы это выглядело правильно.
'cell.textLabel.text.text'? – nhgrif
Не совсем ясно, что вы пытаетесь сделать, или ваш вопрос. – rdelmar
@nhgrif Fixed :) – envinyater