美文网首页
当 TableView 的 Cell 改变时,如何以动画的形式呈

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

作者: 夏天爱大树 | 来源:发表于2017-03-16 21:04 被阅读125次

点击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];
}

相关文章

网友评论

      本文标题:当 TableView 的 Cell 改变时,如何以动画的形式呈

      本文链接:https://www.haomeiwen.com/subject/eoqsnttx.html