2012-05-08 13 views
0

をスクロールした後、アップミキシング私はUITextFieldUILabelsUIButtonsでカスタムUITableViewCellを作成しました。 UITextFieldに値を入力してスクロールすると、それが消えて別のランダムなセルに表示されます。同じ問題が私のUIButtonで発生します。それを押すと、状態は変化しますが、下にスクロールすると消えます。ここでカスタムUITableViewCellsのUITextFieldには、

は私cellForRowAtIndexPathです:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"produktCell"; 
    //NSString *CellIdentifier = [NSString stringWithFormat:@"produktCell %d",indexPath.row]; 

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

    if (cell == nil) { 
      NSLog(@"wird neu erstellt"); 
     cell = [[ProduktTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 



    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

    cell.produktnameLabel.text = [managedObject valueForKey:@"produktname"]; 



    if ([[managedObject valueForKey:@"vondatum"] length] > 1){ 
     cell.vonDatumLabel.text = [managedObject valueForKey:@"vondatum"]; 
     cell.bisDatumLabel.text = [managedObject valueForKey:@"bisdatum"]; 

    }else { 
     cell.vonDatumLabel.text = dateString; 
     cell.bisDatumLabel.text = dateString1; 
    } 


     cell.datumButton.tag = indexPath.row; 
    cell.warenkorbButton.tag = indexPath.row; 
    cell.menge.tag = indexPath.row + 437812; 
    cell.mengeLabel.text = [managedObject valueForKey:@"mengelabel"]; 
    cell.produktnameLabel.tag = indexPath.row +22333; 
    cell.mengeLabel.tag =indexPath.row; 


    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
    NSLocale *german = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"]; 
    [formatter setLocale:german]; 
    [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 
    [formatter setMinimumFractionDigits:2]; 
    [formatter setMaximumFractionDigits:2]; 


    NSNumber *firstNumber = [managedObject valueForKey:@"preis"]; 

    cell.preisLabel.text = [formatter stringFromNumber:firstNumber]; 



    return cell; 
} 

編集:私はテキストフィールドに私の問題を修正しました。私はちょうど方法を削除する:

/*- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView 
{ 


    [[self.tableView superview] endEditing:YES]; 


}*/ 

私のボタンにはまだ問題があります。

答えて

0

私の最高の推測は、再使用されているセルが、ちょうどやりとりしたセルの同じ動作を受信して​​いることです。あなたは私が何を意味するかを素早く試すことができます。このコメント:

編集:この代わりに入れて

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

    if (cell == nil) { 
      NSLog(@"wird neu erstellt"); 
     cell = [[ProduktTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

ProduktTableViewCell *cell = [[ProduktTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

新しい細胞が前のセルと同じ "状態" を取得することはできませんこの方法です。次に何をする必要があるのは、あなたがどのセルを作業しているかを知ることです。それ以外にも、新しいセルの状態をリセットする必要があります。 終了するには、コメントした内容のコメントを外してください(あなたの細胞を再利用可能にしたいので)

+0

私はこの行をコメントすると同じ動作をします。テーブルビューはまだ混ざります。 –

+0

私の編集をチェックしてください。 – Peres

+0

私はそれを試しましたが、(セル== nil)に入ることができません。テーブルビューは空でNSLogは呼び出されません。 –

関連する問題