2

UITextField から特定の値を保存しようとしていますが、スクロールするたびに UITextField に何もないため、保存できません。カスタムセルを使用しています。カスタム セルを特定のビューに読み込む必要があることを理解しています。そのため、textFieldDidEndEditing を使用して値を配列に格納しています。ただし、次のエラー メッセージが表示されます: * キャッチされない例外 'NSInvalidArgumentException' によりアプリを終了しています。

助けていただければ幸いです!! 私のコードは以下のとおりで、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];
}
4

3 に答える 3

0

すべての CellIdentifier を使用するだけで、次のように使用方法が異なりCellIdentifierます

また、ここでこのコードを使用した後、配列を作成してオブジェクトを挿入する必要がないため、配列を作成しないで、このコードを使用してください..

 NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d",indexPath.section,indexPath.row];

「TextCell」や「ButtonCell」などの別のインスタンスの代わりに、この CellIndentifier を使用します

これがお役に立てば幸いです...

:)

于 2012-10-02T04:37:41.490 に答える
0

の値を空の文字列に初期化します。

clientS = @"";
productS = @"";
dateS = @"";
amountS = @"";
qtyS = @"";
taxS = @"";
totalS = @"";
于 2012-10-02T03:59:37.470 に答える
0

テーブルビューに静的セルを実装しようとしているように、コードから見えます。検討したいことは、ストーリーボードを使用し、Interface Builder を使用するだけで静的なテーブル セルをサポートするテーブル ビューを作成することです。これにより、メソッド全体を削除できますcellForRowAtIndexPath:。ストーリーボードを使用できない場合は、現在の方法でセルを管理する必要がありますが、私の本では、コードを削除できるときはいつでもそうする必要があります。

ストーリーボードを使用する場合は、知っておくべきことがいくつかあります。

  • ストーリーボードのビュー コントローラーは、テーブル ビュー コントローラーである必要があります
  • テーブルのコンテンツ フィールドを「静的セル」に設定します。
  • 使用するテキストフィールドを、追加するセルにドラッグして、各セルに追加します
  • ビュー コントローラー ヘッダーにアウトレットを作成し、インターフェイス ビルダーでそれらに接続をドラッグします。

静的セルを含むテーブル ビューの使用に関するチュートリアルがいくつかあります。それらは少し長くなる可能性がありますが、それらに固執することで、探している結果を生み出すことができるはずです.

よろしくお願いします。

于 2012-10-02T05:16:18.787 に答える