1
今、私は、0のインデックスでグローバルに宣言されたアイテム配列を更新してから、テーブルビューの行をインデックス0に更新しないと、テーブルビューのラベルにテキストを表示していますが、他の行を更新して更新します。また、私は上向きにテーブルビューをスクロールすると、すべてのインデックスのインデックス0の値を示します。ここuitableviewのラベルにテキストをリロードする
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(45, 8, 100, 25)];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.font = [UIFont fontWithName:@"Arial" size:16];
[cell addSubview:nameLabel];
deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame= CGRectMake(3, 3, 30, 30);
[deleteButton setImage: [UIImage imageNamed:@"cross_btn.png"] forState:UIControlStateNormal];
[cell addSubview:deleteButton];
priceMark = [[UILabel alloc]initWithFrame:CGRectMake(200, 8, 60, 25)]; //150, 8, 65, 25
priceMark.backgroundColor = [UIColor clearColor];
priceMark.font = [UIFont fontWithName:@"Arial" size:14];
[cell addSubview:priceMark];
qtyLabel = [[UILabel alloc]initWithFrame:CGRectMake(160, 8, 65, 25)]; //225, 8, 60, 25
qtyLabel.backgroundColor = [UIColor clearColor];
qtyLabel.font = [UIFont fontWithName:@"Arial" size:14];
[cell addSubview:qtyLabel];
}
nameLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"itemname"];
priceMark.text = [NSString stringWithFormat:@"Rs: %@",[[itemsArray
objectAtIndex:indexPath.row] objectForKey:@"amount"]];
qtyLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"qty"];
return cell;
}
あなたが追加したラベル/ボタンへの参照を失うされ、これが起こっていました。それらを "タグ"で保持することで、それらをフェッチして値を更新することができます – samfisher