@interface ViewController ()
@property(nonatomic, retain) NSIndexPath* selectedIndexPath;
@end
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary* item = [self.list objectAtIndex:indexPath.row];
ExpandedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ExpandedCell"];
cell.clipsToBounds = YES;
// Populate cell
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return self.selectedIndexPath != nil && self.selectedIndexPath.row == indexPath.row ? expanded_height : normal_height;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableview beginUpdates];
if (self.selectedIndexPath == nil) {
self.selectedIndexPath = indexPath;
} else {
self.selectedIndexPath = nil;
}
[self.tableview endUpdates];
}
No hay comentarios:
Publicar un comentario