I have cells that expand by changing their height
I want to open more information like small view of every cell selection , expanding table view cell.
We selected the cell have to expand and close again while we clicked again.
I am using below code , it is working fine but how to show hidden view on particular cell position.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// UILabel *label = nil;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
// cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
}
StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:indexPath.row];
//If this is the selected index then calculate the height of the cell based on the amount of text we have
if(selectedIndex == indexPath.row)
{
UILabel *cellLabeltotaldays12=[[UILabel alloc]initWithFrame:CGRectMake(520, 80, 100, 12)];
cellLabeltotaldays12.font =[ UIFont systemFontOfSize:14];
cellLabeltotaldays12.text=student.totaldays;
[cell addSubview:cellLabeltotaldays12];
}
else {
//Otherwise just return the minimum height for the label.
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//The user is selecting the cell which is currently expanded
//we want to minimize it back
if(selectedIndex == indexPath.row)
{
selectedIndex = -1;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
//First we check if a cell is already expanded.
//If it is we want to minimize make sure it is reloaded to minimize it back
if(selectedIndex >= 0)
{
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
}
//Finally set the selected index to the new selection and reload it to expand
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}