0

こんにちは、私はカスタムtableview cellsと呼ばれるproduct cell,rating cell,notify cell,whereで使用された場所がproduct cell含まれています。問題は、現在の にテキストを入力した場合です。スクロールすると、現在の印象をテキストで残しました..みんな助けてくれませんか.以下はコードですtextfieldsection 0,1,2,4textfiledssection 0textfiledssection1,2

  -(ProductCell *)getProductCell
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ProductCell" owner:nil options:nil];
    ProductCell  *cell;
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[ProductCell  class]])
        {
            cell= (ProductCell*)currentObject;
            return cell;
        }
    }
    return nil;
}
-(RatingCell *)getRatingCell
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RatingCell" owner:nil options:nil];
    RatingCell  *cell;
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[RatingCell  class]])
        {
            cell= (RatingCell*)currentObject;
            return cell;
        }
    }
    return nil;
}

-(NotifyCell *)getNotifyCell
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NotifyCell" owner:nil options:nil];
    NotifyCell  *cell;
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[NotifyCell  class]])
        {
            cell= (NotifyCell *)currentObject;
            return cell;
        }
    }
    return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier1 = @"Cell1";
    static NSString *CellIdentifier2 = @"Cell2";
    static NSString *CellIdentifier3 = @"Cell3";

    ProductCell *productCell;
    NotifyCell *notifyCell;
    productCell=(ProductCell *)[tblAddProducts dequeueReusableCellWithIdentifier:CellIdentifier1];
    notifyCell = (NotifyCell*)[tblAddProducts dequeueReusableCellWithIdentifier:CellIdentifier2];


    UINib * nib1 = [UINib nibWithNibName:@"ProductCell" bundle: nil];
    [tableView registerNib:nib1 forCellReuseIdentifier:CellIdentifier1];

    UINib * nib2 = [UINib nibWithNibName:@"NotifyCell" bundle: nil];
    [tableView registerNib:nib2 forCellReuseIdentifier:CellIdentifier2];

    UINib * nib3 = [UINib nibWithNibName:@"RatingCell" bundle: nil];
   [tableView registerNib:nib3 forCellReuseIdentifier:CellIdentifier3];


    if (notifyCell == nil)
    {
    notifyCell = [self getNotifyCell];
    }
    if (ratingCell == nil)
    {
    ratingCell = [self getRatingCell];
    }
    if (productCell == nil)
    {
        productCell = [self getProductCell];
    }


    productCell.txtField.delegate=self;
    productCell.selectionStyle = UITableViewCellSelectionStyleNone;
    notifyCell.selectionStyle  = UITableViewCellSelectionStyleNone;
    ratingCell.selectionStyle  = UITableViewCellSelectionStyleNone;

    switch (indexPath.section) {
        case 0:
        productCell.lblName.text=[productTitleArray objectAtIndex:indexPath.row];
        productCell.txtField.tag=indexPath.row;

        if([productCell.lblName.text isEqualToString:@"Valid till"]) productCell.txtField.returnKeyType = UIReturnKeyDone;
        else productCell.txtField.returnKeyType = UIReturnKeyNext;
        cellSection = indexPath.section;
        return productCell;
        break;

        case 1:
        productCell.lblName.text=[invoiceTitleArray objectAtIndex:indexPath.row];
        productCell.txtField.tag=indexPath.row;
        if ([productCell.lblName.text isEqualToString:@"Bank Name"]) productCell.txtField.returnKeyType = UIReturnKeyDone;
        else productCell.txtField.returnKeyType = UIReturnKeyNext;
        cellSection = indexPath.section;
        return productCell;
        break;

        case 2:
        productCell.lblName.text=[warrantyTitleArray objectAtIndex:indexPath.row];
        productCell.txtField.tag=indexPath.row;
        if ([productCell.lblName.text isEqualToString:@"Valid till"]) productCell.txtField.returnKeyType = UIReturnKeyDone;
        else productCell.txtField.returnKeyType = UIReturnKeyNext;
        cellSection = indexPath.section;
        return productCell;
        break;

        case 3:
        productCell.lblName.text=@"Description";
        productCell.txtField.tag=indexPath.row;
        if ([productCell.lblName.text isEqualToString:@"Description"]) productCell.txtField.returnKeyType = UIReturnKeyDone;
        cellSection = indexPath.section;
        return productCell;
        break;

        case 4:
        ratingCell.lblName.text=@"Rating";
        ratingCell.starRatingControl.delegate=self;
        cellSection = indexPath.section;
        return ratingCell;
        break;

        case 5:
        productCell.lblName.text=[serviceContactsTitleArray objectAtIndex:indexPath.row];
        productCell.txtField.tag=indexPath.row;
        if ([productCell.lblName.text isEqualToString:@"Email"]) productCell.txtField.returnKeyType = UIReturnKeyDone;
        else productCell.txtField.returnKeyType = UIReturnKeyNext;
        cellSection = indexPath.section;
        return productCell;
        break;

        case 6:
        notifyCell.lblName.text=[notifyTitleArray objectAtIndex:indexPath.row];
        cellSection = indexPath.section;
        return notifyCell;
        break;
        default:
        break;
    }
    productCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return productCell;
    }
4

1 に答える 1

0

テーブル ビューのセルが再利用されています。これは、テーブル ビュー セルが最適化される方法です。

テーブル ビューに含まれるセクションと行の数が正確にわかっていて、それらが変更されない場合は、フォームにも適した静的なテーブル ビュー セルの使用を検討してください。

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html

The Technique for Static Row Contentセクションを見てください。

それ以外の場合は、各テキスト フィールドの値を評価、電子メール、説明などの変数に保存し、それぞれのテーブル ビュー セルが読み込まれるたびにテキスト フィールドに戻す必要があります。

于 2013-05-22T04:50:22.913 に答える