0
テーブルの再読み込みに問題があります。私cellForRowAtIndexPath
は次のとおりです。UITableView再読み込み
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
int counter=indexPath.row;
NSString *CellIdentifier = [NSString stringWithFormat:@"%d",counter];
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
//ID
UILabel *lblID=[[UILabel alloc]init];
lblID.frame=CGRectMake(10, 15.0, 150, 30.0);
[lblID setFont:[UIFont boldSystemFontOfSize:20.0]];
[lblID setBackgroundColor:[UIColor clearColor]];
[lblID setTextColor:[UIColor blackColor]];
lblID.text = [arrID objectAtIndex:indexPath.row];
[cell.contentView addSubview:lblID];
[lblID release];
//Date
UILabel *lblName=[[UILabel alloc]init];
lblName.frame=CGRectMake(130, 15.0, 250, 30.0);
[lblName setFont:[UIFont systemFontOfSize:20.0]];
[lblName setBackgroundColor:[UIColor clearColor]];
[lblName setTextColor:[UIColor blackColor]];
lblName.text = [arrProductName objectAtIndex:indexPath.row];
[cell.contentView addSubview:lblName];
[lblName release];
//Qty
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(320, 20, 50, 30)];
[textField addTarget:self action:@selector(TextOfTextField:)
forControlEvents:UIControlEventEditingDidEnd];
textField.userInteractionEnabled = true;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.text = [arrItems objectAtIndex:indexPath.row];
textField.tag = indexPath.row;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypePhonePad;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[arrTxtItems addObject:textField];
[cell.contentView addSubview:textField];
[textField release];
//Discount
UITextField *txtDiscount = [[UITextField alloc] initWithFrame:CGRectMake(460, 20, 50, 30)];
// [txtDiscount addTarget:self action:@selector(TextOfTextField:)
// forControlEvents:UIControlEventEditingDidEnd];
txtDiscount.userInteractionEnabled = true;
txtDiscount.borderStyle = UITextBorderStyleRoundedRect;
txtDiscount.font = [UIFont systemFontOfSize:15];
txtDiscount.text = [arrDiscount objectAtIndex:indexPath.row];
txtDiscount.tag = indexPath.row;
txtDiscount.autocorrectionType = UITextAutocorrectionTypeNo;
txtDiscount.keyboardType = UIKeyboardTypePhonePad;
txtDiscount.returnKeyType = UIReturnKeyDone;
txtDiscount.clearButtonMode = UITextFieldViewModeWhileEditing;
txtDiscount.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txtDiscount.delegate = self;
[arrTxtDiscount addObject:txtDiscount];
[cell.contentView addSubview:txtDiscount];
[txtDiscount release];
//Price
UILabel *lblPrice=[[UILabel alloc]init];
lblPrice.frame=CGRectMake(560, 15.0, 250, 30.0);
[lblPrice setFont:[UIFont boldSystemFontOfSize:20.0]];
[lblPrice setBackgroundColor:[UIColor clearColor]];
[lblPrice setTextColor:[UIColor blackColor]];
[arrLblNetPrice addObject:lblPrice];
NSString *strPrice = [arrPrice objectAtIndex:indexPath.row];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setGroupingSeparator:@"."];
[formatter setGroupingSize:2];
[formatter setUsesGroupingSeparator:YES];
[formatter setSecondaryGroupingSize:3];
NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[strPrice doubleValue]]];
[formatter release];
NSLog(@"str : %@",str);
NSLog(@"strPrice : %@",strPrice);
lblPrice.text = str;
[cell.contentView addSubview:lblPrice];
[lblPrice release];
}
return cell;
}
構造化セルこの方法は、私はテーブルをスクロールするとき、私はTextFieldの値を保持するのに役立ちます。しかし、ある時点でテーブルを再ロードすると、のセルがまだリリースされていないため、には入りません。この状態でどこで細胞を放出すべきですか?
@nitish、私はあなたが 'indexPath.row'に基づいてセル識別子を設定していることに気付きました。すべてのセルが同じ種類のセル(同じサブビューの同じクラス)であるため、すべてのセルに同じ識別子を使用する必要があります。各セルに一意の識別子を使用することで、iOSに組み込まれているセルキャッシングの最適化の目的を克服しています。詳細については、Appleのドキュメントを参照してください。 – XJones