iphone - UITextField 在 UITableView 中滚动时清除 - 自定义单元格

标签 iphone ios uitableview

我试图从 UITextField 中保存某些值,但是我无法做到这一点,因为每当我滚动时,UITextField 中什么都没有。我正在使用自定义单元格。我知道自定义单元格必须加载到特定 View 中,因此我使用 textFieldDidEndEditing 将值存储在数组中。但是,我收到以下错误消息:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSArrayM insertObject:atIndex:]: 对象不能为 nil'

非常感谢您的帮助!我的代码在下面,我在 IOS 开发中很新。

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

  if (indexPath.section == 0) {
    if (indexPath.row == 7) {
      static NSString *CellIdentifier = @"RevButtonCell";

      RevButtonCell *cell = (RevButtonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

      if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RevButtonCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
        [cell.revsaveB addTarget:self action:@selector(revaddparse:) forControlEvents:UIControlEventTouchUpInside];

        cell.reveditdeleteB.hidden = YES;
        cell.reveditsaveB.hidden = YES;
        cell.revsaveB.hidden = NO;
        cell.revdeleteB.hidden = NO;

      }
      return cell;
    } else {

      static NSString *CellIdentifier = @"TextCell";

      TextCell *cell = (TextCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

      if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TextCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
      }

      cell.detaillabel.text = [revdetailsA objectAtIndex:indexPath.row];

      cell.detailtext.placeholder = @"Enter Text";
      cell.detailtext.tag = indexPath.row;
      cell.detailtext.delegate = self;

      if (indexPath.row == 0) {
        cell.detailtext.text = dateS;
      }
      if (indexPath.row == 1) {
        cell.detailtext.text = clientS;
      }
      if (indexPath.row == 2) {
        cell.detailtext.text = productS;
      }
      if (indexPath.row == 3) {
        cell.detailtext.text = amountS;
      }
      if (indexPath.row == 4) {
        cell.detailtext.text = qtyS;
      }
      if (indexPath.row == 5) {
        cell.detailtext.text = taxS;
      }
      if (indexPath.row == 6) {
        cell.detailtext.text = totalS;
      }

      cell.selectionStyle = UITableViewCellSelectionStyleNone;

      return cell;
    }
  }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
  [client insertObject:clientS atIndex:0];
  [product insertObject:productS atIndex:0];
  [date insertObject:dateS atIndex:0];
  [amount insertObject:amountS atIndex:0];
  [qty insertObject:qtyS atIndex:0];
  [tax insertObject:taxS atIndex:0];
  [total insertObject:totalS atIndex:0];
}

最佳答案

将 vales 初始化为空字符串

clientS = @"";
productS = @"";
dateS = @"";
amountS = @"";
qtyS = @"";
taxS = @"";
totalS = @"";

关于iphone - UITextField 在 UITableView 中滚动时清除 - 自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12684316/

相关文章:

ios - 包含 UITableView 的 UITableViewCell 的高度(iOS8 和 AutoLayout)

ios - 无法使用 CustomCell 填充 UITableView

ios - 构建失败并显示 "Command PrecompileSwiftBridgingHeader failed with a nonzero exit code"

ios - 为什么应用程序在 NSData getBytes 崩溃?

ios - 启动应用程序时和应用程序运行后,UITableView 中的自动布局结果不同

iphone - 第二次点击按钮不起作用

python - 来自 Socket.IO-Client-Swift 的 Socket.io POST 请求

iphone - iphone/android 特定的 Web 功能是什么?

ios - Xcode 6 - 无法为 Ad-Hoc 分发选择签名证书/配置文件。一直默认

ios - 核心数据模型设计 - 更改 "Live"对象也会更改保存的对象