当 TableView 的 Cell 改变时,如何以动画的形式呈现?

点击cell,改变cell的高度

@interface ViewController ()
@property (nonatomic, strong) NSIndexPath *index;
@end

@implementation ViewController

static NSString *ID = @"cell";
- (void)viewDidLoad {

    [super viewDidLoad];


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if(self.index == indexPath){

        return 120;
    }

    return 60;
}

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

    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
    // 重点是这2句代码实现的功能
    [tableView beginUpdates];
    [tableView endUpdates];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我们在上一篇《通过代码自定义不等高cell》中学习了tableView的相关知识,本文将在上文的基础上,利用sto...
    啊世ka阅读 5,412评论 2 7
  • 今天学的看门狗,初始化配置有: 写保护关闭的使能,状态监听,分频和重载值。在复位前喂狗,老师给我们写全了学生管理系...
    李欣l阅读 1,280评论 0 0
  • 文|一朵程程 1 之前雷斯林在他的公众号上发布了篇文章,题目是《对不起,这些东西一概不外借,希望你问都别问好吗!》...
    小新小新hz阅读 3,836评论 1 1