【问题标题】:iOS not able to update the set text in UITextFieldiOS 无法更新 UITextField 中的设置文本
【发布时间】:2015-08-29 09:17:04
【问题描述】:

我在UITableViewCell 中有一个UITextField,文本属性没有更新。

我的 tableview 委托:

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
KAPInputTableViewCell *cell = [self.registerTableView
                         dequeueReusableCellWithIdentifier:KAPInputCellIdentifier];
if (!cell) {
    cell = [[KAPInputTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                 reuseIdentifier:KAPInputCellIdentifier];
}

switch (indexPath.row) {
    case 0:
        cell.inputTextField.placeholder = KAPLocalizedString(@"email", @"E-mail address");
        cell.inputTextField.text = @"Test";
        cell.tag = 0;
        cell.errorLabel.text = self.emailError;
        self.emailCell = cell;
        self.emailTextField = cell.inputTextField;
        break;
}
cell.inputTextField.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

然后当我打电话时,

NSLog(@"%@", self.emailTextField.text);

稍后在我的 ViewController 中按下按钮,当我更改输入值时,编辑的文本仍然返回“Test”。

请帮忙。

【问题讨论】:

  • 您能否更清楚地解释一下您面临的问题是什么?
  • 我面临的问题是,当我在模拟器中的 UITextField 中输入文本,然后我调用 self.emailField.text 时,文本值不会像实际文本字段中那样更新
  • 您在inputTextField 中将文本设置为@"Test",然后您将inputTextField 文本传递给emailTextField。是吗?
  • 您是否为emailTextField创建了属性?
  • 不,我在编辑字段之前设置文本

标签: ios objective-c iphone uitableview uitextfield


【解决方案1】:

我认为你应该只实现 UITextField 委托方法:

   - (void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@"%@", textField.text);
   }

在这里您将看到您的文本字段已更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 2023-03-03
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多