2011-02-04 14 views
2

グループ化されたUITableViewに小さなフォーム(5フィールド)があります。各UITextFieldは、UITableViewセルの内部にあります。 textFieldをクリックすると、キーボードが表示され、一部のセルを非表示にして、戻したときにその内容が消去されます。UITableViewCell内のUITextFieldがスクロールで消去される

私はそれらが再描画されたと仮定して正しいので、内容はなくなりましたか?もしそうなら、これを防ぐ最良の方法は何ですか?私は5つのフィールドしか持っていないので、スクロールして表示するとセルを再描画する必要がありますか?

私は再利用していた細胞:

static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

    } 

答えて

5

あなたがテキストフィールドの別々の配列を持っているし、あなたにこのような細胞作成のコールバックを実装することができます

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

    } 
    [[cell.contentView subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)]; 

    [cell.contentView addSubview: [textFieldsArray objectsAtIndex: indexPath.row]]; 

    return cell; 

} 
関連する問題