理论依据:http://www.jianshu.com/p/6efc5cf5c569
点击某个cell,高度立即发生变化
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *datas;
NSIndexPath *inp;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
UITableView *tbv = [[UITableViewalloc]initWithFrame:self.view.boundsstyle:UITableViewStylePlain];
[self.viewaddSubview:tbv];
tbv.dataSource =self;
tbv.delegate =self;
datas = [[NSArrayalloc]initWithObjects:@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
returndatas.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(inp) {
if (inp.section == indexPath.section && inp.row == indexPath.row) {
return60 *2.0;
inp =nil;
}
}
return60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
staticNSString *identifier =@"identifier";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];
}
cell.textLabel.text = [datasobjectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPathanimated:TRUE];
//获取当前indexPath并判断对应的Cell是否被选中
inp = indexPath;
//最神奇的地方!!
[tableView beginUpdates];
[tableView endUpdates];
}