views:

48

answers:

0

from my experience in this forum when i ask for something starting with the word "simple" it turns out to be REALLY difficult after all!

at least for a noob like me.

what i would like to do:

  1. tap on a cell and expanded below to show more information in that cell.
  2. tap on an already expanded cell to "restore" it back to its original "normal" cell height.

i have managed to do the first of the two but i m having trouble executing the second.

it might be a "simple" (here comes the dreaded word) thing to do but still having trouble.

could anyone please HELP me? i dont think it is going to be so hard for an experienced developer who wishes to share some of his/her knowledge!

here is the code so far:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;

    if (indexPath.section == SEQUENCES_SECTION) {
  NSUInteger sequencesCount = [entity.sequences count];
        NSInteger row = indexPath.row;

        if (indexPath.row < sequencesCount) {

   static NSString *ParametersCellIdentifier = @"ParametesCell";

   cell = [tableView dequeueReusableCellWithIdentifier:ParametersCellIdentifier];

   if (cell == nil) {
     // Create a cell to display an ingredient.
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ParametersCellIdentifier] autorelease];


   }

            Sequence *sequence = [sequences objectAtIndex:row];
            cell.textLabel.text = sequence.details;
   cell.textLabel.textAlignment = UITextAlignmentLeft;
   cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
   cell.textLabel.numberOfLines = 0;
   cell.textLabel.font = [UIFont systemFontOfSize:12];
   cell.selectionStyle = UITableViewCellSelectionStyleNone;



   UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 42.0)];
   detailTextLabel.font = [UIFont boldSystemFontOfSize:16];
   detailTextLabel.layer.cornerRadius = 8.0;
   detailTextLabel.textAlignment = UITextAlignmentCenter;
   detailTextLabel.text = sequence.name;
   detailTextLabel.backgroundColor = [UIColor lightGrayColor];
   [cell.contentView addSubview:detailTextLabel];
   [detailTextLabel autorelease];



   UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10.0, 1.0 ,42.0, 41.5)];
   imageView.contentMode = UIViewContentModeScaleAspectFit;
   [cell addSubview:imageView];
   imageView.layer.cornerRadius = 8.0;
   //imageView.contentMode = UIViewContentModeScaleAspectFit;
   imageView.layer.masksToBounds = YES;
   imageView.image = sequence.sequenceThumb;
   [imageView autorelease];

{...}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSInteger section = indexPath.section;
    UIViewController *nextViewController = nil;


 switch (section) {
        case SEQUENCES_SECTION:
   selectedCellIndexPath = indexPath;  

   [tableView beginUpdates];
   [tableView endUpdates];
   break;

{...}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {


 CGFloat height = 44.0;

 if (indexPath.section == SEQUENCES_SECTION) {

  if(selectedCellIndexPath != nil  
        && [selectedCellIndexPath compare:indexPath] == NSOrderedSame)  

        return 240;    
 }

{...}