ios - 像 Twitter 应用一样展开表格 View 单元格

标签 ios animation twitter uitableview

我希望在选择推文时具有与 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 应用程序如何处理这些动画内容?

最佳答案

您想用动画重新加载该单元格:

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

关于ios - 像 Twitter 应用一样展开表格 View 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967696/

相关文章:

ios - 在解除分配时尝试加载 View Controller 的 View

ios - 如何使自定义键盘扩展再次成为第一响应者

ios - 字典比较数组

java - fragment 内的 ViewFlipper

objective-c - 从 iOS 的边缘拖动时,如何模拟 Android OS 中的边缘发光动画?

ios - 无法将条形按钮链接到父类(super class)中的@IBAction

javascript - React native - 嵌入 Twitter

python - 如何使用 Streaming API 通过 Twitter 跟踪 400 个关键字?

java - Twitter4j 接口(interface)和类结构

android - 动画完成后我该怎么做?