1

選択されていないときに UITableViewCell が contentView をアニメーション化しない理由を理解するのに苦労しています。

セルを展開および折りたたむコードをいくつか作成しましたが、セルを折りたたむと、高さはアニメーション化されますが、contentView はアニメーション化されません。実際には contentView が削除されているようです。

記録のために、UILabel を contentView に追加しました。展開すると、それに応じて UILabel のフレームのサイズが変更されますが、折りたたむと、UILabel はアニメーションなしで閉じられるか非表示になります。

何かアドバイス?

サンプルコードは次のとおりです。

/* Expanding and collapsing code */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([self cellIsSelected:indexPath])
    {
        //Item is clicked, unclick it
        [self.selectedIndexes removeObject:indexPath];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    else
    {
        //Item is not clicked. Deselect others and select this
        [self.selectedIndexes removeAllObjects];
        [self.selectedIndexes addObject:indexPath];
    }

    [tableView beginUpdates];
    [tableView endUpdates];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self cellIsSelected:indexPath]) {
        return 150;
    }
    return [tableView rowHeight];
}
4

2 に答える 2

0

これを試してください、それが役立つことを願っています

   -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     if(add == NO)// i took bool to compare change it for your need 
      {
      [self.aTableVIew deselectRowAtIndexPath:indexPath animated:YES];
//you need do deletions witin this commit and begin

[self.aTableVIew beginUpdates];
//animations are within beginUpdates and endUpdates otherwise no animations
[array removeObjectAtIndex:indexPath.row];
[self.aTableVIew deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.aTableVIew endUpdates];
    add = YES;
}
else
{

//else in your case add objects to array and reload the table
    [array removeAllObjects];
    [self.aTableVIew reloadData];
    [self.aTableVIew beginUpdates];
 //compute where to insert
    [array addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
    [self.aTableVIew insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
    [self.aTableVIew endUpdates];
    add = NO;
}  
}


于 2013-07-29T05:31:09.187 に答える
0

私が作った私のデモを見てください。セクション ヘッダーのアクションをクリックして、サンプル プロジェクトを折りたたんだり展開したりするだけです。

折りたたんで展開する

これがあなたを助けますように。

于 2013-07-29T05:37:26.720 に答える