2012-01-26 18 views
0

UItableViewがあります。セルを追加および削除できます。 cell.textLabel.textのプロパティを変更できます。私は私のcell.textLabel.text ...セルが削除されると、UITableViewCellsのテキストラベルがセルに設定されます。

enter image description here

と私はTOPセルを削除した場合、そのセルのtextLabel

enter image description here

...テーブルの上に移動し、セルに設定され得るために13を追加した場合

どうすればこの問題を解決できますか?私は、セルを削除してそれを自分自身で保つことができるようにしたい。textLabel。ここに私のcellForRowメソッドが必要な場合:

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

    cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease]; 

     addBtn = [[UIButton alloc]init]; 
     addBtn =[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [addBtn setFrame:CGRectMake(220,10,25,55)]; 
     [addBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside]; 
     [addBtn setTitle:@"+" forState:UIControlStateNormal]; 
     [addBtn setEnabled:YES]; 
     [cell addSubview:addBtn]; 

     subBtn = [[UIButton alloc]init]; 
     subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [subBtn setFrame:CGRectMake(260,10,25,55)]; 
     [subBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside]; 
     [subBtn setTitle:@"-" forState:UIControlStateNormal]; 
     [subBtn setEnabled:YES]; 
     [cell addSubview:subBtn]; 
    } 
    //cellText.hidden=!self.editing; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    cell.imageView.image = [imageArray objectAtIndex:indexPath.row]; 
    cell.tag = indexPath.row; // Important for identifying the cell easily later 
    cell.textLabel.text = [self.number objectAtIndex:indexPath.row]; 

return cell; 
} 

ご協力いただきありがとうございます!

答えて

2

セルを削除すると、UITableViewとその中のすべてのセルが再描画されます。セルが削除された時点で、データソース配列内のオブジェクトがテーブルセルの新しいインデックスに対応するように、データソース(該当する場合は配列self.number)から対応するオブジェクトを削除する必要があります。

+0

は完璧に機能します。本当にありがとう!! – iProRage