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

2017-03-16  本文已影响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];
}
上一篇 下一篇

猜你喜欢

热点阅读