无法设置cell.textField.text的值

时间:2018-02-16 12:25:34

标签: objective-c uitableview uitextfield

我有一个表视图控制器,在视图控制器加载时我需要设置的单元格中有一些文本字段和标签。我无法设置cell.textField.text的值。

当我设置所有文本字段的值时,它们仍然保留(空)。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        AZUserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserDetail"
                                                                    forIndexPath:indexPath];

        switch (indexPath.row) {
            case AZUserCellTypeFirstName:
                cell.label.text = @"First name:";
                cell.textField.placeholder = @"First name";
                if (self.user) {
                    cell.textField.text = self.user.firstName;
                }
                NSLog(@"cell.textField.text = %@", cell);
                NSLog(@"self.user.firstName = %@", self.user.firstName);
                NSLog(@"cell.textField.text = %@", cell.textField.text);
                break;

            case AZUserCellTypeLastName:
                cell.label.text = @"Last name:";
                cell.textField.placeholder = @"Last name";
                cell.textField.text = self.user.lastName;
                break;

            case AZUserCellTypeMail:
                cell.label.text = @"Mail:";
                cell.textField.placeholder = @"Mail";
                cell.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
                cell.textField.returnKeyType = UIReturnKeyDone;
                cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
                cell.textField.text = self.user.mail;
                break;

            default:
                break;
        }

        [self.textfieldsArray addObject:cell.textField];

        return cell;
    }

>     2018-02-16 12:56:03.082837+0100 AZStudents[46627:15399177] cell.textField.text = <AZUserTableViewCell: 0x7fe477832800; baseClass
> = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x608000237480>>
>     2018-02-16 12:56:03.700539+0100 AZStudents[46627:15399177] self.user.firstName = Hgg
>     2018-02-16 12:56:04.314029+0100 AZStudents[46627:15399177] cell.textField.text = (null)

0 个答案:

没有答案