5

行を拡張して補足コンテンツを追加するというツイートを選択するときに、Twitterアプリと同じ動作をしたいと思います。

したがって、これは基本的な行のサイズ変更だけではありません。私は2つの異なるカスタムセルが必要だと思うので、私はそのようなことをしました:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath compare:self.selectedIndexPath] != NSOrderedSame) {
        FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstCell"];
        if (!cell) {
            cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FirstCell"];
        }

        cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];

        return cell;
    }
    else {
        SecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecondCell"];
        if (!cell) {
            cell = [[SecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SecondCell"];
        }

        cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];
        cell.lastnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"lastname"];

        return cell;
    }

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([indexPath compare:self.selectedIndexPath] == NSOrderedSame) {
        return 80.0;
    } else {
        return 44.0;
    }
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedIndexPath = indexPath;

    [tableView reloadData];
}

ここでの私の問題は、Twitterアプリのような流動的なアニメーションを維持したいということです。これは私の場合ではありません[tableView reloadData](2つの異なるカスタムセルがあるので必須だと思います)。

だから誰かが私の必要な回避策を知っているか、あるいは誰かがTwitterアプリがこのアニメーションのものをどのように処理しているか知っていますか?

4

3 に答える 3

7

そのセルをアニメーションでリロードします。

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
于 2013-02-19T21:30:30.353 に答える
4
[tableView beginUpdates];
[tableView endUpdates];

これにより、tableView 全体のセル行サイズの更新がトリガーされます....参照元: iPhone - コンテンツの更新を含む UITableViewCell の高さ変更のスムーズなアニメーション

ハッピーコーディング!

于 2013-02-19T21:26:14.503 に答える